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 { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 143 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 144 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 145 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 146 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 147 | if (successor_ == nullptr) { |
| 148 | __ jmp(GetReturnLabel()); |
| 149 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 150 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 151 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 154 | Label* GetReturnLabel() { |
| 155 | DCHECK(successor_ == nullptr); |
| 156 | return &return_label_; |
| 157 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 158 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 159 | HBasicBlock* GetSuccessor() const { |
| 160 | return successor_; |
| 161 | } |
| 162 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 163 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 164 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 165 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 166 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 167 | Label return_label_; |
| 168 | |
| 169 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 170 | }; |
| 171 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 172 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 173 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 174 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 175 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 176 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 177 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 178 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 179 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 181 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 182 | // Live registers will be restored in the catch block if caught. |
| 183 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 184 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 185 | // Are we using an array length from memory? |
| 186 | HInstruction* array_length = instruction_->InputAt(1); |
| 187 | Location length_loc = locations->InAt(1); |
| 188 | InvokeRuntimeCallingConvention calling_convention; |
| 189 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 190 | // Load the array length into our temporary. |
| 191 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 192 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 193 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 194 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 195 | // Check for conflicts with index. |
| 196 | if (length_loc.Equals(locations->InAt(0))) { |
| 197 | // We know we aren't using parameter 2. |
| 198 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 199 | } |
| 200 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 201 | if (mirror::kUseStringCompression) { |
| 202 | __ andl(length_loc.AsRegister<CpuRegister>(), Immediate(INT32_MAX)); |
| 203 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 204 | } |
| 205 | |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 206 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 207 | // move resolver. |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 208 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 209 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 210 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 211 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 212 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 213 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 214 | Primitive::kPrimInt); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 215 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 216 | ? kQuickThrowStringBounds |
| 217 | : kQuickThrowArrayBounds; |
| 218 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 219 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 220 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 221 | } |
| 222 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 223 | bool IsFatal() const OVERRIDE { return true; } |
| 224 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 225 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 226 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 227 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 228 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 229 | }; |
| 230 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 231 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 232 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 233 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 234 | HInstruction* at, |
| 235 | uint32_t dex_pc, |
| 236 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 237 | : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 238 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 239 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 240 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 241 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 242 | LocationSummary* locations = at_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 243 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 244 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 245 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 246 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 247 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 248 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 249 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 250 | x86_64_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage : kQuickInitializeType, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 251 | at_, |
| 252 | dex_pc_, |
| 253 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 254 | if (do_clinit_) { |
| 255 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 256 | } else { |
| 257 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 258 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 259 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 260 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 261 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 262 | if (out.IsValid()) { |
| 263 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 264 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 267 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 268 | __ jmp(GetExitLabel()); |
| 269 | } |
| 270 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 271 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 272 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 273 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 274 | // The class this slow path will load. |
| 275 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 276 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 277 | // The instruction where this slow path is happening. |
| 278 | // (Might be the load class or an initialization check). |
| 279 | HInstruction* const at_; |
| 280 | |
| 281 | // The dex PC of `at_`. |
| 282 | const uint32_t dex_pc_; |
| 283 | |
| 284 | // Whether to initialize the class. |
| 285 | const bool do_clinit_; |
| 286 | |
| 287 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 288 | }; |
| 289 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 290 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
| 291 | public: |
| 292 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
| 293 | |
| 294 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 295 | LocationSummary* locations = instruction_->GetLocations(); |
| 296 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 297 | |
| 298 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 299 | __ Bind(GetEntryLabel()); |
| 300 | SaveLiveRegisters(codegen, locations); |
| 301 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 302 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 303 | // Custom calling convention: RAX serves as both input and output. |
| 304 | __ movl(CpuRegister(RAX), Immediate(string_index)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 305 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
| 306 | instruction_, |
| 307 | instruction_->GetDexPc(), |
| 308 | this); |
| 309 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 310 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 311 | RestoreLiveRegisters(codegen, locations); |
| 312 | |
| 313 | // Store the resolved String to the BSS entry. |
| 314 | __ movl(Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false), |
| 315 | locations->Out().AsRegister<CpuRegister>()); |
| 316 | Label* fixup_label = x86_64_codegen->NewStringBssEntryPatch(instruction_->AsLoadString()); |
| 317 | __ Bind(fixup_label); |
| 318 | |
| 319 | __ jmp(GetExitLabel()); |
| 320 | } |
| 321 | |
| 322 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 323 | |
| 324 | private: |
| 325 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 326 | }; |
| 327 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 328 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 330 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 331 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 332 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 333 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 334 | LocationSummary* locations = instruction_->GetLocations(); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 335 | Location arg0, arg1; |
| 336 | if (instruction_->IsInstanceOf()) { |
| 337 | arg0 = locations->InAt(1); |
| 338 | arg1 = locations->Out(); |
| 339 | } else { |
| 340 | arg0 = locations->InAt(0); |
| 341 | arg1 = locations->InAt(1); |
| 342 | } |
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 | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 357 | codegen->EmitParallelMoves(arg0, |
| 358 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 359 | Primitive::kPrimNot, |
| 360 | arg1, |
| 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 | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 365 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Class*, 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) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 970 | switch (desired_dispatch_info.code_ptr_location) { |
| 971 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 972 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 973 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 974 | return HInvokeStaticOrDirect::DispatchInfo { |
| 975 | desired_dispatch_info.method_load_kind, |
| 976 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 977 | desired_dispatch_info.method_load_data, |
| 978 | 0u |
| 979 | }; |
| 980 | default: |
| 981 | return desired_dispatch_info; |
| 982 | } |
| 983 | } |
| 984 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 985 | Location CodeGeneratorX86_64::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 986 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 987 | // All registers are assumed to be correctly set up. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 988 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 989 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 990 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 991 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 992 | uint32_t offset = |
| 993 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 994 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 995 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 996 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 997 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 998 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 999 | break; |
| 1000 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 1001 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 1002 | break; |
| 1003 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 1004 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1005 | method_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 1006 | invoke->GetTargetMethod().dex_method_index); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1007 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 1008 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1009 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1010 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 1011 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1012 | // Bind a new fixup label at the end of the "movl" insn. |
| 1013 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 1014 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFile(), offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1015 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1016 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1017 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1018 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1019 | Register method_reg; |
| 1020 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 1021 | if (current_method.IsRegister()) { |
| 1022 | method_reg = current_method.AsRegister<Register>(); |
| 1023 | } else { |
| 1024 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 1025 | DCHECK(!current_method.IsValid()); |
| 1026 | method_reg = reg.AsRegister(); |
| 1027 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 1028 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1029 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1030 | __ movq(reg, |
| 1031 | Address(CpuRegister(method_reg), |
| 1032 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 1033 | // temp = temp[index_in_cache]; |
| 1034 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 1035 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1036 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 1037 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1038 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1039 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 1040 | return callee_method; |
| 1041 | } |
| 1042 | |
| 1043 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 1044 | Location temp) { |
| 1045 | // All registers are assumed to be correctly set up. |
| 1046 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1047 | |
| 1048 | switch (invoke->GetCodePtrLocation()) { |
| 1049 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 1050 | __ call(&frame_entry_label_); |
| 1051 | break; |
| 1052 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1053 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 1054 | invoke->GetTargetMethod().dex_method_index); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1055 | Label* label = &relative_call_patches_.back().label; |
| 1056 | __ call(label); // Bind to the patch label, override at link time. |
| 1057 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 1058 | break; |
| 1059 | } |
| 1060 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 1061 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 1062 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 1063 | LOG(FATAL) << "Unsupported"; |
| 1064 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1065 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 1066 | // (callee_method + offset_of_quick_compiled_code)() |
| 1067 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1068 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1069 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1070 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1071 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1072 | |
| 1073 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1074 | } |
| 1075 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1076 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 1077 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1078 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1079 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1080 | |
| 1081 | // Use the calling convention instead of the location of the receiver, as |
| 1082 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1083 | // slow path, the arguments have been moved to the right place, so here we are |
| 1084 | // guaranteed that the receiver is the first register of the calling convention. |
| 1085 | InvokeDexCallingConvention calling_convention; |
| 1086 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1087 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1088 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1089 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1090 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1091 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1092 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1093 | // emit a read barrier for the previous class reference load. |
| 1094 | // However this is not required in practice, as this is an |
| 1095 | // intermediate/temporary reference and because the current |
| 1096 | // concurrent copying collector keeps the from-space memory |
| 1097 | // intact/accessible until the end of the marking phase (the |
| 1098 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1099 | __ MaybeUnpoisonHeapReference(temp); |
| 1100 | // temp = temp->GetMethodAt(method_offset); |
| 1101 | __ movq(temp, Address(temp, method_offset)); |
| 1102 | // call temp->GetEntryPoint(); |
| 1103 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1104 | kX86_64PointerSize).SizeValue())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1107 | void CodeGeneratorX86_64::RecordSimplePatch() { |
| 1108 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 1109 | simple_patches_.emplace_back(); |
| 1110 | __ Bind(&simple_patches_.back()); |
| 1111 | } |
| 1112 | } |
| 1113 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1114 | void CodeGeneratorX86_64::RecordBootStringPatch(HLoadString* load_string) { |
| 1115 | DCHECK(GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1116 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 1117 | __ Bind(&string_patches_.back().label); |
| 1118 | } |
| 1119 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1120 | void CodeGeneratorX86_64::RecordTypePatch(HLoadClass* load_class) { |
| 1121 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 1122 | __ Bind(&type_patches_.back().label); |
| 1123 | } |
| 1124 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1125 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
| 1126 | DCHECK(!GetCompilerOptions().IsBootImage()); |
| 1127 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 1128 | return &string_patches_.back().label; |
| 1129 | } |
| 1130 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1131 | Label* CodeGeneratorX86_64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 1132 | uint32_t element_offset) { |
| 1133 | // Add a patch entry and return the label. |
| 1134 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 1135 | return &pc_relative_dex_cache_patches_.back().label; |
| 1136 | } |
| 1137 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1138 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 1139 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 1140 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 1141 | |
| 1142 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 1143 | inline void CodeGeneratorX86_64::EmitPcRelativeLinkerPatches( |
| 1144 | const ArenaDeque<PatchInfo<Label>>& infos, |
| 1145 | ArenaVector<LinkerPatch>* linker_patches) { |
| 1146 | for (const PatchInfo<Label>& info : infos) { |
| 1147 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1148 | linker_patches->push_back( |
| 1149 | Factory(literal_offset, &info.dex_file, info.label.Position(), info.index)); |
| 1150 | } |
| 1151 | } |
| 1152 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1153 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 1154 | DCHECK(linker_patches->empty()); |
| 1155 | size_t size = |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1156 | method_patches_.size() + |
| 1157 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1158 | pc_relative_dex_cache_patches_.size() + |
| 1159 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1160 | string_patches_.size() + |
| 1161 | type_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1162 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1163 | for (const PatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1164 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1165 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1166 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1167 | for (const PatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1168 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1169 | linker_patches->push_back( |
| 1170 | LinkerPatch::RelativeCodePatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1171 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1172 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 1173 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1174 | for (const Label& label : simple_patches_) { |
| 1175 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1176 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 1177 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1178 | if (!GetCompilerOptions().IsBootImage()) { |
| 1179 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_patches_, linker_patches); |
| 1180 | } else { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1181 | // These are always PC-relative, see GetSupportedLoadStringKind(). |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1182 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1183 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1184 | // These are always PC-relative, see GetSupportedLoadClassKind(). |
| 1185 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(type_patches_, linker_patches); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1188 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1189 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1193 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1194 | } |
| 1195 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1196 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1197 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1198 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1199 | } |
| 1200 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1201 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1202 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1203 | return kX86_64WordSize; |
| 1204 | } |
| 1205 | |
| 1206 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1207 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1208 | return kX86_64WordSize; |
| 1209 | } |
| 1210 | |
| 1211 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1212 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1213 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1214 | } |
| 1215 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1216 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1217 | HInstruction* instruction, |
| 1218 | uint32_t dex_pc, |
| 1219 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1220 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1221 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1222 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1223 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1224 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1225 | } |
| 1226 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1227 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1228 | HInstruction* instruction, |
| 1229 | SlowPathCode* slow_path) { |
| 1230 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1231 | GenerateInvokeRuntime(entry_point_offset); |
| 1232 | } |
| 1233 | |
| 1234 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1235 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
| 1236 | } |
| 1237 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1238 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1239 | // Use a fake return address register to mimic Quick. |
| 1240 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1241 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1242 | const X86_64InstructionSetFeatures& isa_features, |
| 1243 | const CompilerOptions& compiler_options, |
| 1244 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1245 | : CodeGenerator(graph, |
| 1246 | kNumberOfCpuRegisters, |
| 1247 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1248 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1249 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1250 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1251 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1252 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1253 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1254 | compiler_options, |
| 1255 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1256 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1257 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1258 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1259 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1260 | assembler_(graph->GetArena()), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1261 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1262 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1263 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1264 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1265 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1266 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1267 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1268 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Nicolas Geoffray | ac3ebc3 | 2016-10-05 13:13:50 +0100 | [diff] [blame] | 1269 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1270 | jit_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1271 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1272 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1273 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1274 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1275 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1276 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1277 | assembler_(codegen->GetAssembler()), |
| 1278 | codegen_(codegen) {} |
| 1279 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1280 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1281 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1282 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1283 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1284 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1285 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1286 | } |
| 1287 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1288 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1289 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1290 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1291 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1292 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1293 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1294 | } |
| 1295 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1296 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1297 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1298 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1299 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1300 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1301 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1302 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1303 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1304 | __ testq(CpuRegister(RAX), Address( |
| 1305 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1306 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1307 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1308 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1309 | if (HasEmptyFrame()) { |
| 1310 | return; |
| 1311 | } |
| 1312 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1313 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1314 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1315 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1316 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1317 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1318 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1319 | } |
| 1320 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1321 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1322 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1323 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1324 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1325 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1326 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1327 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1328 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1329 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1330 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1331 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1332 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1333 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1334 | } |
| 1335 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1336 | // Save the current method if we need it. Note that we do not |
| 1337 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1338 | // in the SSA graph. |
| 1339 | if (RequiresCurrentMethod()) { |
| 1340 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1341 | CpuRegister(kMethodRegisterArgument)); |
| 1342 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1346 | __ cfi().RememberState(); |
| 1347 | if (!HasEmptyFrame()) { |
| 1348 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1349 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1350 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1351 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1352 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1353 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1354 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1359 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1360 | __ cfi().AdjustCFAOffset(-adjust); |
| 1361 | |
| 1362 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1363 | Register reg = kCoreCalleeSaves[i]; |
| 1364 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1365 | __ popq(CpuRegister(reg)); |
| 1366 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1367 | __ cfi().Restore(DWARFReg(reg)); |
| 1368 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1369 | } |
| 1370 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1371 | __ ret(); |
| 1372 | __ cfi().RestoreState(); |
| 1373 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1374 | } |
| 1375 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1376 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1377 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1378 | } |
| 1379 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1380 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1381 | if (source.Equals(destination)) { |
| 1382 | return; |
| 1383 | } |
| 1384 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1385 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1386 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1387 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1388 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1389 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1390 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1391 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1392 | } else if (source.IsConstant()) { |
| 1393 | HConstant* constant = source.GetConstant(); |
| 1394 | if (constant->IsLongConstant()) { |
| 1395 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1396 | } else { |
| 1397 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1398 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1399 | } else { |
| 1400 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1401 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1402 | } |
| 1403 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1404 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1405 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1406 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1407 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1408 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1409 | } else if (source.IsConstant()) { |
| 1410 | HConstant* constant = source.GetConstant(); |
| 1411 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1412 | if (constant->IsFloatConstant()) { |
| 1413 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1414 | } else { |
| 1415 | Load64BitValue(dest, value); |
| 1416 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1417 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1418 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1419 | } else { |
| 1420 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1421 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1422 | } |
| 1423 | } else if (destination.IsStackSlot()) { |
| 1424 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1425 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1426 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1427 | } else if (source.IsFpuRegister()) { |
| 1428 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1429 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1430 | } else if (source.IsConstant()) { |
| 1431 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1432 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1433 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1434 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1435 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1436 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1437 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1438 | } |
| 1439 | } else { |
| 1440 | DCHECK(destination.IsDoubleStackSlot()); |
| 1441 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1442 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1443 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1444 | } else if (source.IsFpuRegister()) { |
| 1445 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1446 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1447 | } else if (source.IsConstant()) { |
| 1448 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1449 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1450 | int64_t value = GetInt64ValueOf(constant); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1451 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1452 | } else { |
| 1453 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1454 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1455 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1456 | } |
| 1457 | } |
| 1458 | } |
| 1459 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1460 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1461 | DCHECK(location.IsRegister()); |
| 1462 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1463 | } |
| 1464 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1465 | void CodeGeneratorX86_64::MoveLocation( |
| 1466 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1467 | Move(dst, src); |
| 1468 | } |
| 1469 | |
| 1470 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1471 | if (location.IsRegister()) { |
| 1472 | locations->AddTemp(location); |
| 1473 | } else { |
| 1474 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1475 | } |
| 1476 | } |
| 1477 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1478 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1479 | DCHECK(!successor->IsExitBlock()); |
| 1480 | |
| 1481 | HBasicBlock* block = got->GetBlock(); |
| 1482 | HInstruction* previous = got->GetPrevious(); |
| 1483 | |
| 1484 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1485 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1486 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1487 | return; |
| 1488 | } |
| 1489 | |
| 1490 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1491 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1492 | } |
| 1493 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1494 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1495 | } |
| 1496 | } |
| 1497 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1498 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1499 | got->SetLocations(nullptr); |
| 1500 | } |
| 1501 | |
| 1502 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1503 | HandleGoto(got, got->GetSuccessor()); |
| 1504 | } |
| 1505 | |
| 1506 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1507 | try_boundary->SetLocations(nullptr); |
| 1508 | } |
| 1509 | |
| 1510 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1511 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1512 | if (!successor->IsExitBlock()) { |
| 1513 | HandleGoto(try_boundary, successor); |
| 1514 | } |
| 1515 | } |
| 1516 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1517 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1518 | exit->SetLocations(nullptr); |
| 1519 | } |
| 1520 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1521 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1522 | } |
| 1523 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1524 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1525 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1526 | LabelType* true_label, |
| 1527 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1528 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1529 | __ j(kUnordered, true_label); |
| 1530 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1531 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1532 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1533 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1534 | } |
| 1535 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1536 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1537 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1538 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1539 | Location left = locations->InAt(0); |
| 1540 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1541 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1542 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1543 | case Primitive::kPrimBoolean: |
| 1544 | case Primitive::kPrimByte: |
| 1545 | case Primitive::kPrimChar: |
| 1546 | case Primitive::kPrimShort: |
| 1547 | case Primitive::kPrimInt: |
| 1548 | case Primitive::kPrimNot: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1549 | codegen_->GenerateIntCompare(left, right); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1550 | break; |
| 1551 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1552 | case Primitive::kPrimLong: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1553 | codegen_->GenerateLongCompare(left, right); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1554 | break; |
| 1555 | } |
| 1556 | case Primitive::kPrimFloat: { |
| 1557 | if (right.IsFpuRegister()) { |
| 1558 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1559 | } else if (right.IsConstant()) { |
| 1560 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1561 | codegen_->LiteralFloatAddress( |
| 1562 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1563 | } else { |
| 1564 | DCHECK(right.IsStackSlot()); |
| 1565 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1566 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1567 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1568 | break; |
| 1569 | } |
| 1570 | case Primitive::kPrimDouble: { |
| 1571 | if (right.IsFpuRegister()) { |
| 1572 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1573 | } else if (right.IsConstant()) { |
| 1574 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1575 | codegen_->LiteralDoubleAddress( |
| 1576 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1577 | } else { |
| 1578 | DCHECK(right.IsDoubleStackSlot()); |
| 1579 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1580 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1581 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1582 | break; |
| 1583 | } |
| 1584 | default: |
| 1585 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | template<class LabelType> |
| 1590 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1591 | LabelType* true_target_in, |
| 1592 | LabelType* false_target_in) { |
| 1593 | // Generated branching requires both targets to be explicit. If either of the |
| 1594 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1595 | LabelType fallthrough_target; |
| 1596 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1597 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1598 | |
| 1599 | // Generate the comparison to set the CC. |
| 1600 | GenerateCompareTest(condition); |
| 1601 | |
| 1602 | // Now generate the correct jump(s). |
| 1603 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1604 | switch (type) { |
| 1605 | case Primitive::kPrimLong: { |
| 1606 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1607 | break; |
| 1608 | } |
| 1609 | case Primitive::kPrimFloat: { |
| 1610 | GenerateFPJumps(condition, true_target, false_target); |
| 1611 | break; |
| 1612 | } |
| 1613 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1614 | GenerateFPJumps(condition, true_target, false_target); |
| 1615 | break; |
| 1616 | } |
| 1617 | default: |
| 1618 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1619 | } |
| 1620 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1621 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1622 | __ jmp(false_target); |
| 1623 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1624 | |
| 1625 | if (fallthrough_target.IsLinked()) { |
| 1626 | __ Bind(&fallthrough_target); |
| 1627 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1628 | } |
| 1629 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1630 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1631 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1632 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1633 | // conditions if they are materialized due to the complex branching. |
| 1634 | return cond->IsCondition() && |
| 1635 | cond->GetNext() == branch && |
| 1636 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1637 | } |
| 1638 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1639 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1640 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1641 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1642 | LabelType* true_target, |
| 1643 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1644 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1645 | |
| 1646 | if (true_target == nullptr && false_target == nullptr) { |
| 1647 | // Nothing to do. The code always falls through. |
| 1648 | return; |
| 1649 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1650 | // Constant condition, statically compared against "true" (integer value 1). |
| 1651 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1652 | if (true_target != nullptr) { |
| 1653 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1654 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1655 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1656 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1657 | if (false_target != nullptr) { |
| 1658 | __ jmp(false_target); |
| 1659 | } |
| 1660 | } |
| 1661 | return; |
| 1662 | } |
| 1663 | |
| 1664 | // The following code generates these patterns: |
| 1665 | // (1) true_target == nullptr && false_target != nullptr |
| 1666 | // - opposite condition true => branch to false_target |
| 1667 | // (2) true_target != nullptr && false_target == nullptr |
| 1668 | // - condition true => branch to true_target |
| 1669 | // (3) true_target != nullptr && false_target != nullptr |
| 1670 | // - condition true => branch to true_target |
| 1671 | // - branch to false_target |
| 1672 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1673 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1674 | if (true_target == nullptr) { |
| 1675 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1676 | } else { |
| 1677 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1678 | } |
| 1679 | } else { |
| 1680 | // Materialized condition, compare against 0. |
| 1681 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1682 | if (lhs.IsRegister()) { |
| 1683 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1684 | } else { |
| 1685 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1686 | } |
| 1687 | if (true_target == nullptr) { |
| 1688 | __ j(kEqual, false_target); |
| 1689 | } else { |
| 1690 | __ j(kNotEqual, true_target); |
| 1691 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1692 | } |
| 1693 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1694 | // Condition has not been materialized, use its inputs as the |
| 1695 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1696 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1697 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1698 | // If this is a long or FP comparison that has been folded into |
| 1699 | // the HCondition, generate the comparison directly. |
| 1700 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1701 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1702 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1703 | return; |
| 1704 | } |
| 1705 | |
| 1706 | Location lhs = condition->GetLocations()->InAt(0); |
| 1707 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1708 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1709 | if (true_target == nullptr) { |
| 1710 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1711 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1712 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1713 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1714 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1715 | |
| 1716 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1717 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1718 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1719 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1720 | } |
| 1721 | } |
| 1722 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1723 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1724 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1725 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1726 | locations->SetInAt(0, Location::Any()); |
| 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1731 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1732 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1733 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1734 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1735 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1736 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1737 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1741 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1742 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1743 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1744 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1745 | locations->SetInAt(0, Location::Any()); |
| 1746 | } |
| 1747 | } |
| 1748 | |
| 1749 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1750 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1751 | GenerateTestAndBranch<Label>(deoptimize, |
| 1752 | /* condition_input_index */ 0, |
| 1753 | slow_path->GetEntryLabel(), |
| 1754 | /* false_target */ nullptr); |
| 1755 | } |
| 1756 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1757 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1758 | // There are no conditional move instructions for XMMs. |
| 1759 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1760 | return false; |
| 1761 | } |
| 1762 | |
| 1763 | // A FP condition doesn't generate the single CC that we need. |
| 1764 | HInstruction* condition = select->GetCondition(); |
| 1765 | if (condition->IsCondition() && |
| 1766 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1767 | return false; |
| 1768 | } |
| 1769 | |
| 1770 | // We can generate a CMOV for this Select. |
| 1771 | return true; |
| 1772 | } |
| 1773 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1774 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1775 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1776 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1777 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1778 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1779 | } else { |
| 1780 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1781 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1782 | if (select->InputAt(1)->IsConstant()) { |
| 1783 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1784 | } else { |
| 1785 | locations->SetInAt(1, Location::Any()); |
| 1786 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1787 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1788 | locations->SetInAt(1, Location::Any()); |
| 1789 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1790 | } |
| 1791 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1792 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1793 | } |
| 1794 | locations->SetOut(Location::SameAsFirstInput()); |
| 1795 | } |
| 1796 | |
| 1797 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1798 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1799 | if (SelectCanUseCMOV(select)) { |
| 1800 | // If both the condition and the source types are integer, we can generate |
| 1801 | // a CMOV to implement Select. |
| 1802 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1803 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1804 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1805 | |
| 1806 | HInstruction* select_condition = select->GetCondition(); |
| 1807 | Condition cond = kNotEqual; |
| 1808 | |
| 1809 | // Figure out how to test the 'condition'. |
| 1810 | if (select_condition->IsCondition()) { |
| 1811 | HCondition* condition = select_condition->AsCondition(); |
| 1812 | if (!condition->IsEmittedAtUseSite()) { |
| 1813 | // This was a previously materialized condition. |
| 1814 | // Can we use the existing condition code? |
| 1815 | if (AreEflagsSetFrom(condition, select)) { |
| 1816 | // Materialization was the previous instruction. Condition codes are right. |
| 1817 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1818 | } else { |
| 1819 | // No, we have to recreate the condition code. |
| 1820 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1821 | __ testl(cond_reg, cond_reg); |
| 1822 | } |
| 1823 | } else { |
| 1824 | GenerateCompareTest(condition); |
| 1825 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1826 | } |
| 1827 | } else { |
| 1828 | // Must be a boolean condition, which needs to be compared to 0. |
| 1829 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1830 | __ testl(cond_reg, cond_reg); |
| 1831 | } |
| 1832 | |
| 1833 | // If the condition is true, overwrite the output, which already contains false. |
| 1834 | // Generate the correct sized CMOV. |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1835 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1836 | if (value_true_loc.IsRegister()) { |
| 1837 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1838 | } else { |
| 1839 | __ cmov(cond, |
| 1840 | value_false, |
| 1841 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1842 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1843 | } else { |
| 1844 | NearLabel false_target; |
| 1845 | GenerateTestAndBranch<NearLabel>(select, |
| 1846 | /* condition_input_index */ 2, |
| 1847 | /* true_target */ nullptr, |
| 1848 | &false_target); |
| 1849 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1850 | __ Bind(&false_target); |
| 1851 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1854 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1855 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1856 | } |
| 1857 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1858 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1859 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | void CodeGeneratorX86_64::GenerateNop() { |
| 1863 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1864 | } |
| 1865 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1866 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1867 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1868 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1869 | // Handle the long/FP comparisons made in instruction simplification. |
| 1870 | switch (cond->InputAt(0)->GetType()) { |
| 1871 | case Primitive::kPrimLong: |
| 1872 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1873 | locations->SetInAt(1, Location::Any()); |
| 1874 | break; |
| 1875 | case Primitive::kPrimFloat: |
| 1876 | case Primitive::kPrimDouble: |
| 1877 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1878 | locations->SetInAt(1, Location::Any()); |
| 1879 | break; |
| 1880 | default: |
| 1881 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1882 | locations->SetInAt(1, Location::Any()); |
| 1883 | break; |
| 1884 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1885 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1886 | locations->SetOut(Location::RequiresRegister()); |
| 1887 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1888 | } |
| 1889 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1890 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1891 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1892 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1893 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1894 | |
| 1895 | LocationSummary* locations = cond->GetLocations(); |
| 1896 | Location lhs = locations->InAt(0); |
| 1897 | Location rhs = locations->InAt(1); |
| 1898 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1899 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1900 | |
| 1901 | switch (cond->InputAt(0)->GetType()) { |
| 1902 | default: |
| 1903 | // Integer case. |
| 1904 | |
| 1905 | // Clear output register: setcc only sets the low byte. |
| 1906 | __ xorl(reg, reg); |
| 1907 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1908 | codegen_->GenerateIntCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1909 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1910 | return; |
| 1911 | case Primitive::kPrimLong: |
| 1912 | // Clear output register: setcc only sets the low byte. |
| 1913 | __ xorl(reg, reg); |
| 1914 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1915 | codegen_->GenerateLongCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1916 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1917 | return; |
| 1918 | case Primitive::kPrimFloat: { |
| 1919 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1920 | if (rhs.IsConstant()) { |
| 1921 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1922 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1923 | } else if (rhs.IsStackSlot()) { |
| 1924 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1925 | } else { |
| 1926 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1927 | } |
| 1928 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1929 | break; |
| 1930 | } |
| 1931 | case Primitive::kPrimDouble: { |
| 1932 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1933 | if (rhs.IsConstant()) { |
| 1934 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1935 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1936 | } else if (rhs.IsDoubleStackSlot()) { |
| 1937 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1938 | } else { |
| 1939 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1940 | } |
| 1941 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1942 | break; |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1947 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1948 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1949 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1950 | __ Bind(&false_label); |
| 1951 | __ xorl(reg, reg); |
| 1952 | __ jmp(&done_label); |
| 1953 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1954 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1955 | __ Bind(&true_label); |
| 1956 | __ movl(reg, Immediate(1)); |
| 1957 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1961 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1965 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1969 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1973 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1977 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1981 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1985 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1989 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1993 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1997 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2001 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2005 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2006 | } |
| 2007 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2008 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2009 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2013 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2017 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2021 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2025 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2029 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2033 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2037 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2040 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2041 | LocationSummary* locations = |
| 2042 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2043 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2044 | case Primitive::kPrimBoolean: |
| 2045 | case Primitive::kPrimByte: |
| 2046 | case Primitive::kPrimShort: |
| 2047 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2048 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2049 | case Primitive::kPrimLong: { |
| 2050 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2051 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2052 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2053 | break; |
| 2054 | } |
| 2055 | case Primitive::kPrimFloat: |
| 2056 | case Primitive::kPrimDouble: { |
| 2057 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2058 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2059 | locations->SetOut(Location::RequiresRegister()); |
| 2060 | break; |
| 2061 | } |
| 2062 | default: |
| 2063 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2064 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2068 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2069 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2070 | Location left = locations->InAt(0); |
| 2071 | Location right = locations->InAt(1); |
| 2072 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2073 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2074 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2075 | Condition less_cond = kLess; |
| 2076 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2077 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2078 | case Primitive::kPrimBoolean: |
| 2079 | case Primitive::kPrimByte: |
| 2080 | case Primitive::kPrimShort: |
| 2081 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2082 | case Primitive::kPrimInt: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2083 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2084 | break; |
| 2085 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2086 | case Primitive::kPrimLong: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2087 | codegen_->GenerateLongCompare(left, right); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2088 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2089 | } |
| 2090 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2091 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2092 | if (right.IsConstant()) { |
| 2093 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2094 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2095 | } else if (right.IsStackSlot()) { |
| 2096 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2097 | } else { |
| 2098 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2099 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2100 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2101 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2102 | break; |
| 2103 | } |
| 2104 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2105 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2106 | if (right.IsConstant()) { |
| 2107 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2108 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2109 | } else if (right.IsDoubleStackSlot()) { |
| 2110 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2111 | } else { |
| 2112 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2113 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2114 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2115 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2116 | break; |
| 2117 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2118 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2119 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2120 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2121 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2122 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2123 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2124 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2125 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2126 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2127 | __ movl(out, Immediate(1)); |
| 2128 | __ jmp(&done); |
| 2129 | |
| 2130 | __ Bind(&less); |
| 2131 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2132 | |
| 2133 | __ Bind(&done); |
| 2134 | } |
| 2135 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2136 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2137 | LocationSummary* locations = |
| 2138 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2139 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2140 | } |
| 2141 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2142 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2143 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2144 | } |
| 2145 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2146 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2147 | LocationSummary* locations = |
| 2148 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2149 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2150 | } |
| 2151 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2152 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2153 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2156 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2157 | LocationSummary* locations = |
| 2158 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2159 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2162 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2163 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2164 | } |
| 2165 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2166 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2167 | LocationSummary* locations = |
| 2168 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2169 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2170 | } |
| 2171 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2172 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2173 | // Will be generated at use site. |
| 2174 | } |
| 2175 | |
| 2176 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2177 | LocationSummary* locations = |
| 2178 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2179 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2180 | } |
| 2181 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2182 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2183 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2184 | // Will be generated at use site. |
| 2185 | } |
| 2186 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2187 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2188 | memory_barrier->SetLocations(nullptr); |
| 2189 | } |
| 2190 | |
| 2191 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2192 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2193 | } |
| 2194 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2195 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2196 | ret->SetLocations(nullptr); |
| 2197 | } |
| 2198 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2199 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2200 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2204 | LocationSummary* locations = |
| 2205 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2206 | switch (ret->InputAt(0)->GetType()) { |
| 2207 | case Primitive::kPrimBoolean: |
| 2208 | case Primitive::kPrimByte: |
| 2209 | case Primitive::kPrimChar: |
| 2210 | case Primitive::kPrimShort: |
| 2211 | case Primitive::kPrimInt: |
| 2212 | case Primitive::kPrimNot: |
| 2213 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2214 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2215 | break; |
| 2216 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2217 | case Primitive::kPrimFloat: |
| 2218 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2219 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2220 | break; |
| 2221 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2222 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2223 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2224 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2228 | if (kIsDebugBuild) { |
| 2229 | switch (ret->InputAt(0)->GetType()) { |
| 2230 | case Primitive::kPrimBoolean: |
| 2231 | case Primitive::kPrimByte: |
| 2232 | case Primitive::kPrimChar: |
| 2233 | case Primitive::kPrimShort: |
| 2234 | case Primitive::kPrimInt: |
| 2235 | case Primitive::kPrimNot: |
| 2236 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2237 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2238 | break; |
| 2239 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2240 | case Primitive::kPrimFloat: |
| 2241 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2242 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2243 | XMM0); |
| 2244 | break; |
| 2245 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2246 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2247 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2248 | } |
| 2249 | } |
| 2250 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2251 | } |
| 2252 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2253 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2254 | switch (type) { |
| 2255 | case Primitive::kPrimBoolean: |
| 2256 | case Primitive::kPrimByte: |
| 2257 | case Primitive::kPrimChar: |
| 2258 | case Primitive::kPrimShort: |
| 2259 | case Primitive::kPrimInt: |
| 2260 | case Primitive::kPrimNot: |
| 2261 | case Primitive::kPrimLong: |
| 2262 | return Location::RegisterLocation(RAX); |
| 2263 | |
| 2264 | case Primitive::kPrimVoid: |
| 2265 | return Location::NoLocation(); |
| 2266 | |
| 2267 | case Primitive::kPrimDouble: |
| 2268 | case Primitive::kPrimFloat: |
| 2269 | return Location::FpuRegisterLocation(XMM0); |
| 2270 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2271 | |
| 2272 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2276 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2277 | } |
| 2278 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2279 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2280 | switch (type) { |
| 2281 | case Primitive::kPrimBoolean: |
| 2282 | case Primitive::kPrimByte: |
| 2283 | case Primitive::kPrimChar: |
| 2284 | case Primitive::kPrimShort: |
| 2285 | case Primitive::kPrimInt: |
| 2286 | case Primitive::kPrimNot: { |
| 2287 | uint32_t index = gp_index_++; |
| 2288 | stack_index_++; |
| 2289 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2290 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2291 | } else { |
| 2292 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2293 | } |
| 2294 | } |
| 2295 | |
| 2296 | case Primitive::kPrimLong: { |
| 2297 | uint32_t index = gp_index_; |
| 2298 | stack_index_ += 2; |
| 2299 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2300 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2301 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2302 | } else { |
| 2303 | gp_index_ += 2; |
| 2304 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2305 | } |
| 2306 | } |
| 2307 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2308 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2309 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2310 | stack_index_++; |
| 2311 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2312 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2313 | } else { |
| 2314 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2315 | } |
| 2316 | } |
| 2317 | |
| 2318 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2319 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2320 | stack_index_ += 2; |
| 2321 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2322 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2323 | } else { |
| 2324 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2325 | } |
| 2326 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2327 | |
| 2328 | case Primitive::kPrimVoid: |
| 2329 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2330 | break; |
| 2331 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2332 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2333 | } |
| 2334 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2335 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2336 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2337 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2338 | // the method_idx. |
| 2339 | HandleInvoke(invoke); |
| 2340 | } |
| 2341 | |
| 2342 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2343 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2344 | } |
| 2345 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2346 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2347 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2348 | // art::PrepareForRegisterAllocation. |
| 2349 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2350 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2351 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2352 | if (intrinsic.TryDispatch(invoke)) { |
| 2353 | return; |
| 2354 | } |
| 2355 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2356 | HandleInvoke(invoke); |
| 2357 | } |
| 2358 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2359 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2360 | if (invoke->GetLocations()->Intrinsified()) { |
| 2361 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2362 | intrinsic.Dispatch(invoke); |
| 2363 | return true; |
| 2364 | } |
| 2365 | return false; |
| 2366 | } |
| 2367 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2368 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2369 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2370 | // art::PrepareForRegisterAllocation. |
| 2371 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2372 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2373 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2374 | return; |
| 2375 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2376 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2377 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2378 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2379 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2380 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2381 | } |
| 2382 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2383 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2384 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2385 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
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::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2389 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2390 | if (intrinsic.TryDispatch(invoke)) { |
| 2391 | return; |
| 2392 | } |
| 2393 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2394 | HandleInvoke(invoke); |
| 2395 | } |
| 2396 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2397 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2398 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2399 | return; |
| 2400 | } |
| 2401 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2402 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2403 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2404 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2405 | } |
| 2406 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2407 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2408 | HandleInvoke(invoke); |
| 2409 | // Add the hidden argument. |
| 2410 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2411 | } |
| 2412 | |
| 2413 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2414 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2415 | LocationSummary* locations = invoke->GetLocations(); |
| 2416 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2417 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2418 | Location receiver = locations->InAt(0); |
| 2419 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2420 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2421 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2422 | // won't be modified thereafter, before the `call` instruction. |
| 2423 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2424 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2425 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2426 | if (receiver.IsStackSlot()) { |
| 2427 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2428 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2429 | __ movl(temp, Address(temp, class_offset)); |
| 2430 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2431 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2432 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2433 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2434 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2435 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2436 | // emit a read barrier for the previous class reference load. |
| 2437 | // However this is not required in practice, as this is an |
| 2438 | // intermediate/temporary reference and because the current |
| 2439 | // concurrent copying collector keeps the from-space memory |
| 2440 | // intact/accessible until the end of the marking phase (the |
| 2441 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2442 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2443 | // temp = temp->GetAddressOfIMT() |
| 2444 | __ movq(temp, |
| 2445 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2446 | // temp = temp->GetImtEntryAt(method_offset); |
| 2447 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2448 | invoke->GetImtIndex(), kX86_64PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2449 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2450 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2451 | // call temp->GetEntryPoint(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2452 | __ call(Address( |
| 2453 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2454 | |
| 2455 | DCHECK(!codegen_->IsLeafMethod()); |
| 2456 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2457 | } |
| 2458 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2459 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2460 | LocationSummary* locations = |
| 2461 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2462 | switch (neg->GetResultType()) { |
| 2463 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2464 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2465 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2466 | locations->SetOut(Location::SameAsFirstInput()); |
| 2467 | break; |
| 2468 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2469 | case Primitive::kPrimFloat: |
| 2470 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2471 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2472 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2473 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2474 | break; |
| 2475 | |
| 2476 | default: |
| 2477 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2482 | LocationSummary* locations = neg->GetLocations(); |
| 2483 | Location out = locations->Out(); |
| 2484 | Location in = locations->InAt(0); |
| 2485 | switch (neg->GetResultType()) { |
| 2486 | case Primitive::kPrimInt: |
| 2487 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2488 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2489 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2490 | break; |
| 2491 | |
| 2492 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2493 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2494 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2495 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2496 | break; |
| 2497 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2498 | case Primitive::kPrimFloat: { |
| 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 float negation with an exclusive or with value |
| 2502 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2503 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2504 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2505 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2506 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2507 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2508 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2509 | case Primitive::kPrimDouble: { |
| 2510 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2511 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2512 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2513 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2514 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2515 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2516 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2517 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2518 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2519 | |
| 2520 | default: |
| 2521 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2522 | } |
| 2523 | } |
| 2524 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2525 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2526 | LocationSummary* locations = |
| 2527 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2528 | Primitive::Type result_type = conversion->GetResultType(); |
| 2529 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2530 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2531 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2532 | // The Java language does not allow treating boolean as an integral type but |
| 2533 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2534 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2535 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2536 | case Primitive::kPrimByte: |
| 2537 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2538 | case Primitive::kPrimLong: |
| 2539 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2540 | case Primitive::kPrimBoolean: |
| 2541 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2542 | case Primitive::kPrimShort: |
| 2543 | case Primitive::kPrimInt: |
| 2544 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2545 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2546 | locations->SetInAt(0, Location::Any()); |
| 2547 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2548 | break; |
| 2549 | |
| 2550 | default: |
| 2551 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2552 | << " to " << result_type; |
| 2553 | } |
| 2554 | break; |
| 2555 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2556 | case Primitive::kPrimShort: |
| 2557 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2558 | case Primitive::kPrimLong: |
| 2559 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2560 | case Primitive::kPrimBoolean: |
| 2561 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2562 | case Primitive::kPrimByte: |
| 2563 | case Primitive::kPrimInt: |
| 2564 | case Primitive::kPrimChar: |
| 2565 | // Processing a Dex `int-to-short' instruction. |
| 2566 | locations->SetInAt(0, Location::Any()); |
| 2567 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2568 | break; |
| 2569 | |
| 2570 | default: |
| 2571 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2572 | << " to " << result_type; |
| 2573 | } |
| 2574 | break; |
| 2575 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2576 | case Primitive::kPrimInt: |
| 2577 | switch (input_type) { |
| 2578 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2579 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2580 | locations->SetInAt(0, Location::Any()); |
| 2581 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2582 | break; |
| 2583 | |
| 2584 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2585 | // Processing a Dex `float-to-int' instruction. |
| 2586 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2587 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2588 | break; |
| 2589 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2590 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2591 | // Processing a Dex `double-to-int' instruction. |
| 2592 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2593 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2594 | break; |
| 2595 | |
| 2596 | default: |
| 2597 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2598 | << " to " << result_type; |
| 2599 | } |
| 2600 | break; |
| 2601 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2602 | case Primitive::kPrimLong: |
| 2603 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2604 | case Primitive::kPrimBoolean: |
| 2605 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2606 | case Primitive::kPrimByte: |
| 2607 | case Primitive::kPrimShort: |
| 2608 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2609 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2610 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2611 | // TODO: We would benefit from a (to-be-implemented) |
| 2612 | // Location::RegisterOrStackSlot requirement for this input. |
| 2613 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2614 | locations->SetOut(Location::RequiresRegister()); |
| 2615 | break; |
| 2616 | |
| 2617 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2618 | // Processing a Dex `float-to-long' instruction. |
| 2619 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2620 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2621 | break; |
| 2622 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2623 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2624 | // Processing a Dex `double-to-long' instruction. |
| 2625 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2626 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2627 | break; |
| 2628 | |
| 2629 | default: |
| 2630 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2631 | << " to " << result_type; |
| 2632 | } |
| 2633 | break; |
| 2634 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2635 | case Primitive::kPrimChar: |
| 2636 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2637 | case Primitive::kPrimLong: |
| 2638 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2639 | case Primitive::kPrimBoolean: |
| 2640 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2641 | case Primitive::kPrimByte: |
| 2642 | case Primitive::kPrimShort: |
| 2643 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2644 | // Processing a Dex `int-to-char' instruction. |
| 2645 | locations->SetInAt(0, Location::Any()); |
| 2646 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2647 | break; |
| 2648 | |
| 2649 | default: |
| 2650 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2651 | << " to " << result_type; |
| 2652 | } |
| 2653 | break; |
| 2654 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2655 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2656 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2657 | case Primitive::kPrimBoolean: |
| 2658 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2659 | case Primitive::kPrimByte: |
| 2660 | case Primitive::kPrimShort: |
| 2661 | case Primitive::kPrimInt: |
| 2662 | case Primitive::kPrimChar: |
| 2663 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2664 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2665 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2666 | break; |
| 2667 | |
| 2668 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2669 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2670 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2671 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2672 | break; |
| 2673 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2674 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2675 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2676 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2677 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2678 | break; |
| 2679 | |
| 2680 | default: |
| 2681 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2682 | << " to " << result_type; |
| 2683 | }; |
| 2684 | break; |
| 2685 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2686 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2687 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2688 | case Primitive::kPrimBoolean: |
| 2689 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2690 | case Primitive::kPrimByte: |
| 2691 | case Primitive::kPrimShort: |
| 2692 | case Primitive::kPrimInt: |
| 2693 | case Primitive::kPrimChar: |
| 2694 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2695 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2696 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2697 | break; |
| 2698 | |
| 2699 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2700 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2701 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2702 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2703 | break; |
| 2704 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2705 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2706 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2707 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2708 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2709 | break; |
| 2710 | |
| 2711 | default: |
| 2712 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2713 | << " to " << result_type; |
| 2714 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2715 | break; |
| 2716 | |
| 2717 | default: |
| 2718 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2719 | << " to " << result_type; |
| 2720 | } |
| 2721 | } |
| 2722 | |
| 2723 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2724 | LocationSummary* locations = conversion->GetLocations(); |
| 2725 | Location out = locations->Out(); |
| 2726 | Location in = locations->InAt(0); |
| 2727 | Primitive::Type result_type = conversion->GetResultType(); |
| 2728 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2729 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2730 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2731 | case Primitive::kPrimByte: |
| 2732 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2733 | case Primitive::kPrimLong: |
| 2734 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2735 | case Primitive::kPrimBoolean: |
| 2736 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2737 | case Primitive::kPrimShort: |
| 2738 | case Primitive::kPrimInt: |
| 2739 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2740 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2741 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2742 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2743 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2744 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2745 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2746 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2747 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2748 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2749 | } |
| 2750 | break; |
| 2751 | |
| 2752 | default: |
| 2753 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2754 | << " to " << result_type; |
| 2755 | } |
| 2756 | break; |
| 2757 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2758 | case Primitive::kPrimShort: |
| 2759 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2760 | case Primitive::kPrimLong: |
| 2761 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2762 | case Primitive::kPrimBoolean: |
| 2763 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2764 | case Primitive::kPrimByte: |
| 2765 | case Primitive::kPrimInt: |
| 2766 | case Primitive::kPrimChar: |
| 2767 | // Processing a Dex `int-to-short' instruction. |
| 2768 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2769 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2770 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2771 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2772 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2773 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2774 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2775 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2776 | } |
| 2777 | break; |
| 2778 | |
| 2779 | default: |
| 2780 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2781 | << " to " << result_type; |
| 2782 | } |
| 2783 | break; |
| 2784 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2785 | case Primitive::kPrimInt: |
| 2786 | switch (input_type) { |
| 2787 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2788 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2789 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2790 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2791 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2792 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2793 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2794 | } else { |
| 2795 | DCHECK(in.IsConstant()); |
| 2796 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2797 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2798 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2799 | } |
| 2800 | break; |
| 2801 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2802 | case Primitive::kPrimFloat: { |
| 2803 | // Processing a Dex `float-to-int' instruction. |
| 2804 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2805 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2806 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2807 | |
| 2808 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2809 | // if input >= (float)INT_MAX goto done |
| 2810 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2811 | __ j(kAboveEqual, &done); |
| 2812 | // if input == NaN goto nan |
| 2813 | __ j(kUnordered, &nan); |
| 2814 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2815 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2816 | __ jmp(&done); |
| 2817 | __ Bind(&nan); |
| 2818 | // output = 0 |
| 2819 | __ xorl(output, output); |
| 2820 | __ Bind(&done); |
| 2821 | break; |
| 2822 | } |
| 2823 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2824 | case Primitive::kPrimDouble: { |
| 2825 | // Processing a Dex `double-to-int' instruction. |
| 2826 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2827 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2828 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2829 | |
| 2830 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2831 | // if input >= (double)INT_MAX goto done |
| 2832 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2833 | __ j(kAboveEqual, &done); |
| 2834 | // if input == NaN goto nan |
| 2835 | __ j(kUnordered, &nan); |
| 2836 | // output = double-to-int-truncate(input) |
| 2837 | __ cvttsd2si(output, input); |
| 2838 | __ jmp(&done); |
| 2839 | __ Bind(&nan); |
| 2840 | // output = 0 |
| 2841 | __ xorl(output, output); |
| 2842 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2843 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2844 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2845 | |
| 2846 | default: |
| 2847 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2848 | << " to " << result_type; |
| 2849 | } |
| 2850 | break; |
| 2851 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2852 | case Primitive::kPrimLong: |
| 2853 | switch (input_type) { |
| 2854 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2855 | case Primitive::kPrimBoolean: |
| 2856 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2857 | case Primitive::kPrimByte: |
| 2858 | case Primitive::kPrimShort: |
| 2859 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2860 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2861 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2862 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2863 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2864 | break; |
| 2865 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2866 | case Primitive::kPrimFloat: { |
| 2867 | // Processing a Dex `float-to-long' instruction. |
| 2868 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2869 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2870 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2871 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2872 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2873 | // if input >= (float)LONG_MAX goto done |
| 2874 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2875 | __ j(kAboveEqual, &done); |
| 2876 | // if input == NaN goto nan |
| 2877 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2878 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2879 | __ cvttss2si(output, input, true); |
| 2880 | __ jmp(&done); |
| 2881 | __ Bind(&nan); |
| 2882 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2883 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2884 | __ Bind(&done); |
| 2885 | break; |
| 2886 | } |
| 2887 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2888 | case Primitive::kPrimDouble: { |
| 2889 | // Processing a Dex `double-to-long' instruction. |
| 2890 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2891 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2892 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2893 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2894 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2895 | // if input >= (double)LONG_MAX goto done |
| 2896 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2897 | __ j(kAboveEqual, &done); |
| 2898 | // if input == NaN goto nan |
| 2899 | __ j(kUnordered, &nan); |
| 2900 | // output = double-to-long-truncate(input) |
| 2901 | __ cvttsd2si(output, input, true); |
| 2902 | __ jmp(&done); |
| 2903 | __ Bind(&nan); |
| 2904 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2905 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2906 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2907 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2908 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2909 | |
| 2910 | default: |
| 2911 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2912 | << " to " << result_type; |
| 2913 | } |
| 2914 | break; |
| 2915 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2916 | case Primitive::kPrimChar: |
| 2917 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2918 | case Primitive::kPrimLong: |
| 2919 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2920 | case Primitive::kPrimBoolean: |
| 2921 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2922 | case Primitive::kPrimByte: |
| 2923 | case Primitive::kPrimShort: |
| 2924 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2925 | // Processing a Dex `int-to-char' instruction. |
| 2926 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2927 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2928 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2929 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2930 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2931 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2932 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2933 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2934 | } |
| 2935 | break; |
| 2936 | |
| 2937 | default: |
| 2938 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2939 | << " to " << result_type; |
| 2940 | } |
| 2941 | break; |
| 2942 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2943 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2944 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2945 | case Primitive::kPrimBoolean: |
| 2946 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2947 | case Primitive::kPrimByte: |
| 2948 | case Primitive::kPrimShort: |
| 2949 | case Primitive::kPrimInt: |
| 2950 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2951 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2952 | if (in.IsRegister()) { |
| 2953 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2954 | } else if (in.IsConstant()) { |
| 2955 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2956 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2957 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2958 | } else { |
| 2959 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2960 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2961 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2962 | break; |
| 2963 | |
| 2964 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2965 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2966 | if (in.IsRegister()) { |
| 2967 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2968 | } else if (in.IsConstant()) { |
| 2969 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2970 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2971 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2972 | } else { |
| 2973 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2974 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2975 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2976 | break; |
| 2977 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2978 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2979 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2980 | if (in.IsFpuRegister()) { |
| 2981 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2982 | } else if (in.IsConstant()) { |
| 2983 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2984 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2985 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2986 | } else { |
| 2987 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2988 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2989 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2990 | break; |
| 2991 | |
| 2992 | default: |
| 2993 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2994 | << " to " << result_type; |
| 2995 | }; |
| 2996 | break; |
| 2997 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2998 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2999 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 3000 | case Primitive::kPrimBoolean: |
| 3001 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3002 | case Primitive::kPrimByte: |
| 3003 | case Primitive::kPrimShort: |
| 3004 | case Primitive::kPrimInt: |
| 3005 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3006 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3007 | if (in.IsRegister()) { |
| 3008 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3009 | } else if (in.IsConstant()) { |
| 3010 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3011 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3012 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3013 | } else { |
| 3014 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3015 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3016 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3017 | break; |
| 3018 | |
| 3019 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3020 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3021 | if (in.IsRegister()) { |
| 3022 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3023 | } else if (in.IsConstant()) { |
| 3024 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3025 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3026 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3027 | } else { |
| 3028 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3029 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3030 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3031 | break; |
| 3032 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3033 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3034 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3035 | if (in.IsFpuRegister()) { |
| 3036 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3037 | } else if (in.IsConstant()) { |
| 3038 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3039 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3040 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3041 | } else { |
| 3042 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3043 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3044 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3045 | break; |
| 3046 | |
| 3047 | default: |
| 3048 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3049 | << " to " << result_type; |
| 3050 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3051 | break; |
| 3052 | |
| 3053 | default: |
| 3054 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3055 | << " to " << result_type; |
| 3056 | } |
| 3057 | } |
| 3058 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3059 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3060 | LocationSummary* locations = |
| 3061 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3062 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3063 | case Primitive::kPrimInt: { |
| 3064 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3065 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3066 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3067 | break; |
| 3068 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3069 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3070 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3071 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3072 | // 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] | 3073 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3074 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3075 | break; |
| 3076 | } |
| 3077 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3078 | case Primitive::kPrimDouble: |
| 3079 | case Primitive::kPrimFloat: { |
| 3080 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3081 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3082 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3083 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3084 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3085 | |
| 3086 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3087 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3088 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3092 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3093 | Location first = locations->InAt(0); |
| 3094 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3095 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3096 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3097 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3098 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3099 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3100 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3101 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3102 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3103 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3104 | } else { |
| 3105 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3106 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3107 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3108 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3109 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3110 | __ addl(out.AsRegister<CpuRegister>(), |
| 3111 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3112 | } else { |
| 3113 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3114 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3115 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3116 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3117 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3118 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3119 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3120 | break; |
| 3121 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3122 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3123 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3124 | if (second.IsRegister()) { |
| 3125 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3126 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3127 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3128 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3129 | } else { |
| 3130 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3131 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3132 | } |
| 3133 | } else { |
| 3134 | DCHECK(second.IsConstant()); |
| 3135 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3136 | int32_t int32_value = Low32Bits(value); |
| 3137 | DCHECK_EQ(int32_value, value); |
| 3138 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3139 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3140 | } else { |
| 3141 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3142 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3143 | } |
| 3144 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3145 | break; |
| 3146 | } |
| 3147 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3148 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3149 | if (second.IsFpuRegister()) { |
| 3150 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3151 | } else if (second.IsConstant()) { |
| 3152 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3153 | codegen_->LiteralFloatAddress( |
| 3154 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3155 | } else { |
| 3156 | DCHECK(second.IsStackSlot()); |
| 3157 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3158 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3159 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3160 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3164 | if (second.IsFpuRegister()) { |
| 3165 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3166 | } else if (second.IsConstant()) { |
| 3167 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3168 | codegen_->LiteralDoubleAddress( |
| 3169 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3170 | } else { |
| 3171 | DCHECK(second.IsDoubleStackSlot()); |
| 3172 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3173 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3174 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3175 | break; |
| 3176 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3177 | |
| 3178 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3179 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3184 | LocationSummary* locations = |
| 3185 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3186 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3187 | case Primitive::kPrimInt: { |
| 3188 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3189 | locations->SetInAt(1, Location::Any()); |
| 3190 | locations->SetOut(Location::SameAsFirstInput()); |
| 3191 | break; |
| 3192 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3193 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3194 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3195 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3196 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3197 | break; |
| 3198 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3199 | case Primitive::kPrimFloat: |
| 3200 | case Primitive::kPrimDouble: { |
| 3201 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3202 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3203 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3204 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3205 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3206 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3207 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3208 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3212 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3213 | Location first = locations->InAt(0); |
| 3214 | Location second = locations->InAt(1); |
| 3215 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3216 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3217 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3218 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3219 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3220 | } else if (second.IsConstant()) { |
| 3221 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3222 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3223 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3224 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3225 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3226 | break; |
| 3227 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3228 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3229 | if (second.IsConstant()) { |
| 3230 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3231 | DCHECK(IsInt<32>(value)); |
| 3232 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3233 | } else { |
| 3234 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3235 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3236 | break; |
| 3237 | } |
| 3238 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3239 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3240 | if (second.IsFpuRegister()) { |
| 3241 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3242 | } else if (second.IsConstant()) { |
| 3243 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3244 | codegen_->LiteralFloatAddress( |
| 3245 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3246 | } else { |
| 3247 | DCHECK(second.IsStackSlot()); |
| 3248 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3249 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3250 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3251 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3255 | if (second.IsFpuRegister()) { |
| 3256 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3257 | } else if (second.IsConstant()) { |
| 3258 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3259 | codegen_->LiteralDoubleAddress( |
| 3260 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3261 | } else { |
| 3262 | DCHECK(second.IsDoubleStackSlot()); |
| 3263 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3264 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3265 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3266 | break; |
| 3267 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3268 | |
| 3269 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3270 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3271 | } |
| 3272 | } |
| 3273 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3274 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3275 | LocationSummary* locations = |
| 3276 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3277 | switch (mul->GetResultType()) { |
| 3278 | case Primitive::kPrimInt: { |
| 3279 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3280 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3281 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3282 | // Can use 3 operand multiply. |
| 3283 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3284 | } else { |
| 3285 | locations->SetOut(Location::SameAsFirstInput()); |
| 3286 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3287 | break; |
| 3288 | } |
| 3289 | case Primitive::kPrimLong: { |
| 3290 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3291 | locations->SetInAt(1, Location::Any()); |
| 3292 | if (mul->InputAt(1)->IsLongConstant() && |
| 3293 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3294 | // Can use 3 operand multiply. |
| 3295 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3296 | } else { |
| 3297 | locations->SetOut(Location::SameAsFirstInput()); |
| 3298 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3299 | break; |
| 3300 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3301 | case Primitive::kPrimFloat: |
| 3302 | case Primitive::kPrimDouble: { |
| 3303 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3304 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3305 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3306 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3307 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3308 | |
| 3309 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3310 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3311 | } |
| 3312 | } |
| 3313 | |
| 3314 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3315 | LocationSummary* locations = mul->GetLocations(); |
| 3316 | Location first = locations->InAt(0); |
| 3317 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3318 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3319 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3320 | case Primitive::kPrimInt: |
| 3321 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3322 | // problems where the output may not be the same as the first operand. |
| 3323 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3324 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3325 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3326 | } else if (second.IsRegister()) { |
| 3327 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3328 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3329 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3330 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3331 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3332 | __ imull(first.AsRegister<CpuRegister>(), |
| 3333 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3334 | } |
| 3335 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3336 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3337 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3338 | // problems where the output may not be the same as the first operand. |
| 3339 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3340 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3341 | if (IsInt<32>(value)) { |
| 3342 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3343 | Immediate(static_cast<int32_t>(value))); |
| 3344 | } else { |
| 3345 | // Have to use the constant area. |
| 3346 | DCHECK(first.Equals(out)); |
| 3347 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3348 | } |
| 3349 | } else if (second.IsRegister()) { |
| 3350 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3351 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3352 | } else { |
| 3353 | DCHECK(second.IsDoubleStackSlot()); |
| 3354 | DCHECK(first.Equals(out)); |
| 3355 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3356 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3357 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3358 | break; |
| 3359 | } |
| 3360 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3361 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3362 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3363 | if (second.IsFpuRegister()) { |
| 3364 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3365 | } else if (second.IsConstant()) { |
| 3366 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3367 | codegen_->LiteralFloatAddress( |
| 3368 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3369 | } else { |
| 3370 | DCHECK(second.IsStackSlot()); |
| 3371 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3372 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3373 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3374 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3378 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3379 | if (second.IsFpuRegister()) { |
| 3380 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3381 | } else if (second.IsConstant()) { |
| 3382 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3383 | codegen_->LiteralDoubleAddress( |
| 3384 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3385 | } else { |
| 3386 | DCHECK(second.IsDoubleStackSlot()); |
| 3387 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3388 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3389 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3390 | break; |
| 3391 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3392 | |
| 3393 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3394 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3395 | } |
| 3396 | } |
| 3397 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3398 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3399 | uint32_t stack_adjustment, bool is_float) { |
| 3400 | if (source.IsStackSlot()) { |
| 3401 | DCHECK(is_float); |
| 3402 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3403 | } else if (source.IsDoubleStackSlot()) { |
| 3404 | DCHECK(!is_float); |
| 3405 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3406 | } else { |
| 3407 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3408 | if (is_float) { |
| 3409 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3410 | codegen_->Move(stack_temp, source); |
| 3411 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3412 | } else { |
| 3413 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3414 | codegen_->Move(stack_temp, source); |
| 3415 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3416 | } |
| 3417 | } |
| 3418 | } |
| 3419 | |
| 3420 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3421 | Primitive::Type type = rem->GetResultType(); |
| 3422 | bool is_float = type == Primitive::kPrimFloat; |
| 3423 | size_t elem_size = Primitive::ComponentSize(type); |
| 3424 | LocationSummary* locations = rem->GetLocations(); |
| 3425 | Location first = locations->InAt(0); |
| 3426 | Location second = locations->InAt(1); |
| 3427 | Location out = locations->Out(); |
| 3428 | |
| 3429 | // Create stack space for 2 elements. |
| 3430 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3431 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3432 | |
| 3433 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3434 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3435 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3436 | |
| 3437 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3438 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3439 | __ Bind(&retry); |
| 3440 | __ fprem(); |
| 3441 | |
| 3442 | // Move FP status to AX. |
| 3443 | __ fstsw(); |
| 3444 | |
| 3445 | // And see if the argument reduction is complete. This is signaled by the |
| 3446 | // C2 FPU flag bit set to 0. |
| 3447 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3448 | __ j(kNotEqual, &retry); |
| 3449 | |
| 3450 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3451 | // Store FP top of stack to real stack. |
| 3452 | if (is_float) { |
| 3453 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3454 | } else { |
| 3455 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3456 | } |
| 3457 | |
| 3458 | // Pop the 2 items from the FP stack. |
| 3459 | __ fucompp(); |
| 3460 | |
| 3461 | // Load the value from the stack into an XMM register. |
| 3462 | DCHECK(out.IsFpuRegister()) << out; |
| 3463 | if (is_float) { |
| 3464 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3465 | } else { |
| 3466 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3467 | } |
| 3468 | |
| 3469 | // And remove the temporary stack space we allocated. |
| 3470 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3471 | } |
| 3472 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3473 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3474 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3475 | |
| 3476 | LocationSummary* locations = instruction->GetLocations(); |
| 3477 | Location second = locations->InAt(1); |
| 3478 | DCHECK(second.IsConstant()); |
| 3479 | |
| 3480 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3481 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3482 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3483 | |
| 3484 | DCHECK(imm == 1 || imm == -1); |
| 3485 | |
| 3486 | switch (instruction->GetResultType()) { |
| 3487 | case Primitive::kPrimInt: { |
| 3488 | if (instruction->IsRem()) { |
| 3489 | __ xorl(output_register, output_register); |
| 3490 | } else { |
| 3491 | __ movl(output_register, input_register); |
| 3492 | if (imm == -1) { |
| 3493 | __ negl(output_register); |
| 3494 | } |
| 3495 | } |
| 3496 | break; |
| 3497 | } |
| 3498 | |
| 3499 | case Primitive::kPrimLong: { |
| 3500 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3501 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3502 | } else { |
| 3503 | __ movq(output_register, input_register); |
| 3504 | if (imm == -1) { |
| 3505 | __ negq(output_register); |
| 3506 | } |
| 3507 | } |
| 3508 | break; |
| 3509 | } |
| 3510 | |
| 3511 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3512 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3513 | } |
| 3514 | } |
| 3515 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3516 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3517 | LocationSummary* locations = instruction->GetLocations(); |
| 3518 | Location second = locations->InAt(1); |
| 3519 | |
| 3520 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3521 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3522 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3523 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3524 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3525 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3526 | |
| 3527 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3528 | |
| 3529 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3530 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3531 | __ testl(numerator, numerator); |
| 3532 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3533 | int shift = CTZ(imm); |
| 3534 | __ sarl(tmp, Immediate(shift)); |
| 3535 | |
| 3536 | if (imm < 0) { |
| 3537 | __ negl(tmp); |
| 3538 | } |
| 3539 | |
| 3540 | __ movl(output_register, tmp); |
| 3541 | } else { |
| 3542 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3543 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3544 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3545 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3546 | __ addq(rdx, numerator); |
| 3547 | __ testq(numerator, numerator); |
| 3548 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3549 | int shift = CTZ(imm); |
| 3550 | __ sarq(rdx, Immediate(shift)); |
| 3551 | |
| 3552 | if (imm < 0) { |
| 3553 | __ negq(rdx); |
| 3554 | } |
| 3555 | |
| 3556 | __ movq(output_register, rdx); |
| 3557 | } |
| 3558 | } |
| 3559 | |
| 3560 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3561 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3562 | |
| 3563 | LocationSummary* locations = instruction->GetLocations(); |
| 3564 | Location second = locations->InAt(1); |
| 3565 | |
| 3566 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3567 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3568 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3569 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3570 | : locations->Out().AsRegister<CpuRegister>(); |
| 3571 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3572 | |
| 3573 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3574 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3575 | if (instruction->IsDiv()) { |
| 3576 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3577 | } else { |
| 3578 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3579 | } |
| 3580 | |
| 3581 | int64_t magic; |
| 3582 | int shift; |
| 3583 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3584 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3585 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3586 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3587 | |
| 3588 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3589 | |
| 3590 | __ movl(numerator, eax); |
| 3591 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3592 | __ movl(eax, Immediate(magic)); |
| 3593 | __ imull(numerator); |
| 3594 | |
| 3595 | if (imm > 0 && magic < 0) { |
| 3596 | __ addl(edx, numerator); |
| 3597 | } else if (imm < 0 && magic > 0) { |
| 3598 | __ subl(edx, numerator); |
| 3599 | } |
| 3600 | |
| 3601 | if (shift != 0) { |
| 3602 | __ sarl(edx, Immediate(shift)); |
| 3603 | } |
| 3604 | |
| 3605 | __ movl(eax, edx); |
| 3606 | __ shrl(edx, Immediate(31)); |
| 3607 | __ addl(edx, eax); |
| 3608 | |
| 3609 | if (instruction->IsRem()) { |
| 3610 | __ movl(eax, numerator); |
| 3611 | __ imull(edx, Immediate(imm)); |
| 3612 | __ subl(eax, edx); |
| 3613 | __ movl(edx, eax); |
| 3614 | } else { |
| 3615 | __ movl(eax, edx); |
| 3616 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3617 | } else { |
| 3618 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3619 | |
| 3620 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3621 | |
| 3622 | CpuRegister rax = eax; |
| 3623 | CpuRegister rdx = edx; |
| 3624 | |
| 3625 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3626 | |
| 3627 | // Save the numerator. |
| 3628 | __ movq(numerator, rax); |
| 3629 | |
| 3630 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3631 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3632 | |
| 3633 | // RDX:RAX = magic * numerator |
| 3634 | __ imulq(numerator); |
| 3635 | |
| 3636 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3637 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3638 | __ addq(rdx, numerator); |
| 3639 | } else if (imm < 0 && magic > 0) { |
| 3640 | // RDX -= numerator |
| 3641 | __ subq(rdx, numerator); |
| 3642 | } |
| 3643 | |
| 3644 | // Shift if needed. |
| 3645 | if (shift != 0) { |
| 3646 | __ sarq(rdx, Immediate(shift)); |
| 3647 | } |
| 3648 | |
| 3649 | // RDX += 1 if RDX < 0 |
| 3650 | __ movq(rax, rdx); |
| 3651 | __ shrq(rdx, Immediate(63)); |
| 3652 | __ addq(rdx, rax); |
| 3653 | |
| 3654 | if (instruction->IsRem()) { |
| 3655 | __ movq(rax, numerator); |
| 3656 | |
| 3657 | if (IsInt<32>(imm)) { |
| 3658 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3659 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3660 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | __ subq(rax, rdx); |
| 3664 | __ movq(rdx, rax); |
| 3665 | } else { |
| 3666 | __ movq(rax, rdx); |
| 3667 | } |
| 3668 | } |
| 3669 | } |
| 3670 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3671 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3672 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3673 | Primitive::Type type = instruction->GetResultType(); |
| 3674 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3675 | |
| 3676 | bool is_div = instruction->IsDiv(); |
| 3677 | LocationSummary* locations = instruction->GetLocations(); |
| 3678 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3679 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3680 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3681 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3682 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3683 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3684 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3685 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3686 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3687 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3688 | if (imm == 0) { |
| 3689 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3690 | } else if (imm == 1 || imm == -1) { |
| 3691 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3692 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3693 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3694 | } else { |
| 3695 | DCHECK(imm <= -2 || imm >= 2); |
| 3696 | GenerateDivRemWithAnyConstant(instruction); |
| 3697 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3698 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3699 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3700 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3701 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3702 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3703 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3704 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3705 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3706 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3707 | // so it's safe to just use negl instead of more complex comparisons. |
| 3708 | if (type == Primitive::kPrimInt) { |
| 3709 | __ cmpl(second_reg, Immediate(-1)); |
| 3710 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3711 | // edx:eax <- sign-extended of eax |
| 3712 | __ cdq(); |
| 3713 | // eax = quotient, edx = remainder |
| 3714 | __ idivl(second_reg); |
| 3715 | } else { |
| 3716 | __ cmpq(second_reg, Immediate(-1)); |
| 3717 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3718 | // rdx:rax <- sign-extended of rax |
| 3719 | __ cqo(); |
| 3720 | // rax = quotient, rdx = remainder |
| 3721 | __ idivq(second_reg); |
| 3722 | } |
| 3723 | __ Bind(slow_path->GetExitLabel()); |
| 3724 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3725 | } |
| 3726 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3727 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3728 | LocationSummary* locations = |
| 3729 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3730 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3731 | case Primitive::kPrimInt: |
| 3732 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3733 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3734 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3735 | locations->SetOut(Location::SameAsFirstInput()); |
| 3736 | // Intel uses edx:eax as the dividend. |
| 3737 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3738 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3739 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3740 | // output and request another temp. |
| 3741 | if (div->InputAt(1)->IsConstant()) { |
| 3742 | locations->AddTemp(Location::RequiresRegister()); |
| 3743 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3744 | break; |
| 3745 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3746 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3747 | case Primitive::kPrimFloat: |
| 3748 | case Primitive::kPrimDouble: { |
| 3749 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3750 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3751 | locations->SetOut(Location::SameAsFirstInput()); |
| 3752 | break; |
| 3753 | } |
| 3754 | |
| 3755 | default: |
| 3756 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3757 | } |
| 3758 | } |
| 3759 | |
| 3760 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3761 | LocationSummary* locations = div->GetLocations(); |
| 3762 | Location first = locations->InAt(0); |
| 3763 | Location second = locations->InAt(1); |
| 3764 | DCHECK(first.Equals(locations->Out())); |
| 3765 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3766 | Primitive::Type type = div->GetResultType(); |
| 3767 | switch (type) { |
| 3768 | case Primitive::kPrimInt: |
| 3769 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3770 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3771 | break; |
| 3772 | } |
| 3773 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3774 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3775 | if (second.IsFpuRegister()) { |
| 3776 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3777 | } else if (second.IsConstant()) { |
| 3778 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3779 | codegen_->LiteralFloatAddress( |
| 3780 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3781 | } else { |
| 3782 | DCHECK(second.IsStackSlot()); |
| 3783 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3784 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3785 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3786 | break; |
| 3787 | } |
| 3788 | |
| 3789 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3790 | if (second.IsFpuRegister()) { |
| 3791 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3792 | } else if (second.IsConstant()) { |
| 3793 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3794 | codegen_->LiteralDoubleAddress( |
| 3795 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3796 | } else { |
| 3797 | DCHECK(second.IsDoubleStackSlot()); |
| 3798 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3799 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3800 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3801 | break; |
| 3802 | } |
| 3803 | |
| 3804 | default: |
| 3805 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3806 | } |
| 3807 | } |
| 3808 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3809 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3810 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3811 | LocationSummary* locations = |
| 3812 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3813 | |
| 3814 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3815 | case Primitive::kPrimInt: |
| 3816 | case Primitive::kPrimLong: { |
| 3817 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3818 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3819 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3820 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3821 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3822 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3823 | // output and request another temp. |
| 3824 | if (rem->InputAt(1)->IsConstant()) { |
| 3825 | locations->AddTemp(Location::RequiresRegister()); |
| 3826 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3827 | break; |
| 3828 | } |
| 3829 | |
| 3830 | case Primitive::kPrimFloat: |
| 3831 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3832 | locations->SetInAt(0, Location::Any()); |
| 3833 | locations->SetInAt(1, Location::Any()); |
| 3834 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3835 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3836 | break; |
| 3837 | } |
| 3838 | |
| 3839 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3840 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3841 | } |
| 3842 | } |
| 3843 | |
| 3844 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3845 | Primitive::Type type = rem->GetResultType(); |
| 3846 | switch (type) { |
| 3847 | case Primitive::kPrimInt: |
| 3848 | case Primitive::kPrimLong: { |
| 3849 | GenerateDivRemIntegral(rem); |
| 3850 | break; |
| 3851 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3852 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3853 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3854 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3855 | break; |
| 3856 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3857 | default: |
| 3858 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3859 | } |
| 3860 | } |
| 3861 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3862 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3863 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3864 | locations->SetInAt(0, Location::Any()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3868 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3869 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3870 | codegen_->AddSlowPath(slow_path); |
| 3871 | |
| 3872 | LocationSummary* locations = instruction->GetLocations(); |
| 3873 | Location value = locations->InAt(0); |
| 3874 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3875 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3876 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3877 | case Primitive::kPrimByte: |
| 3878 | case Primitive::kPrimChar: |
| 3879 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3880 | case Primitive::kPrimInt: { |
| 3881 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3882 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3883 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3884 | } else if (value.IsStackSlot()) { |
| 3885 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3886 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3887 | } else { |
| 3888 | DCHECK(value.IsConstant()) << value; |
| 3889 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3890 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3891 | } |
| 3892 | } |
| 3893 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3894 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3895 | case Primitive::kPrimLong: { |
| 3896 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3897 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3898 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3899 | } else if (value.IsDoubleStackSlot()) { |
| 3900 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3901 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3902 | } else { |
| 3903 | DCHECK(value.IsConstant()) << value; |
| 3904 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3905 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3906 | } |
| 3907 | } |
| 3908 | break; |
| 3909 | } |
| 3910 | default: |
| 3911 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3912 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3913 | } |
| 3914 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3915 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3916 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3917 | |
| 3918 | LocationSummary* locations = |
| 3919 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3920 | |
| 3921 | switch (op->GetResultType()) { |
| 3922 | case Primitive::kPrimInt: |
| 3923 | case Primitive::kPrimLong: { |
| 3924 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3925 | // The shift count needs to be in CL. |
| 3926 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3927 | locations->SetOut(Location::SameAsFirstInput()); |
| 3928 | break; |
| 3929 | } |
| 3930 | default: |
| 3931 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3932 | } |
| 3933 | } |
| 3934 | |
| 3935 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3936 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3937 | |
| 3938 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3939 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3940 | Location second = locations->InAt(1); |
| 3941 | |
| 3942 | switch (op->GetResultType()) { |
| 3943 | case Primitive::kPrimInt: { |
| 3944 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3945 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3946 | if (op->IsShl()) { |
| 3947 | __ shll(first_reg, second_reg); |
| 3948 | } else if (op->IsShr()) { |
| 3949 | __ sarl(first_reg, second_reg); |
| 3950 | } else { |
| 3951 | __ shrl(first_reg, second_reg); |
| 3952 | } |
| 3953 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3954 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3955 | if (op->IsShl()) { |
| 3956 | __ shll(first_reg, imm); |
| 3957 | } else if (op->IsShr()) { |
| 3958 | __ sarl(first_reg, imm); |
| 3959 | } else { |
| 3960 | __ shrl(first_reg, imm); |
| 3961 | } |
| 3962 | } |
| 3963 | break; |
| 3964 | } |
| 3965 | case Primitive::kPrimLong: { |
| 3966 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3967 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3968 | if (op->IsShl()) { |
| 3969 | __ shlq(first_reg, second_reg); |
| 3970 | } else if (op->IsShr()) { |
| 3971 | __ sarq(first_reg, second_reg); |
| 3972 | } else { |
| 3973 | __ shrq(first_reg, second_reg); |
| 3974 | } |
| 3975 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3976 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3977 | if (op->IsShl()) { |
| 3978 | __ shlq(first_reg, imm); |
| 3979 | } else if (op->IsShr()) { |
| 3980 | __ sarq(first_reg, imm); |
| 3981 | } else { |
| 3982 | __ shrq(first_reg, imm); |
| 3983 | } |
| 3984 | } |
| 3985 | break; |
| 3986 | } |
| 3987 | default: |
| 3988 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3989 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3990 | } |
| 3991 | } |
| 3992 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3993 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3994 | LocationSummary* locations = |
| 3995 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3996 | |
| 3997 | switch (ror->GetResultType()) { |
| 3998 | case Primitive::kPrimInt: |
| 3999 | case Primitive::kPrimLong: { |
| 4000 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4001 | // The shift count needs to be in CL (unless it is a constant). |
| 4002 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 4003 | locations->SetOut(Location::SameAsFirstInput()); |
| 4004 | break; |
| 4005 | } |
| 4006 | default: |
| 4007 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4008 | UNREACHABLE(); |
| 4009 | } |
| 4010 | } |
| 4011 | |
| 4012 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4013 | LocationSummary* locations = ror->GetLocations(); |
| 4014 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4015 | Location second = locations->InAt(1); |
| 4016 | |
| 4017 | switch (ror->GetResultType()) { |
| 4018 | case Primitive::kPrimInt: |
| 4019 | if (second.IsRegister()) { |
| 4020 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4021 | __ rorl(first_reg, second_reg); |
| 4022 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4023 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4024 | __ rorl(first_reg, imm); |
| 4025 | } |
| 4026 | break; |
| 4027 | case Primitive::kPrimLong: |
| 4028 | if (second.IsRegister()) { |
| 4029 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4030 | __ rorq(first_reg, second_reg); |
| 4031 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4032 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4033 | __ rorq(first_reg, imm); |
| 4034 | } |
| 4035 | break; |
| 4036 | default: |
| 4037 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4038 | UNREACHABLE(); |
| 4039 | } |
| 4040 | } |
| 4041 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4042 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4043 | HandleShift(shl); |
| 4044 | } |
| 4045 | |
| 4046 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4047 | HandleShift(shl); |
| 4048 | } |
| 4049 | |
| 4050 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4051 | HandleShift(shr); |
| 4052 | } |
| 4053 | |
| 4054 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4055 | HandleShift(shr); |
| 4056 | } |
| 4057 | |
| 4058 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4059 | HandleShift(ushr); |
| 4060 | } |
| 4061 | |
| 4062 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4063 | HandleShift(ushr); |
| 4064 | } |
| 4065 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4066 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4067 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4068 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4069 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4070 | if (instruction->IsStringAlloc()) { |
| 4071 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4072 | } else { |
| 4073 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4074 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4075 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4076 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4077 | } |
| 4078 | |
| 4079 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4080 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4081 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4082 | if (instruction->IsStringAlloc()) { |
| 4083 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4084 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4085 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4086 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 4087 | __ call(Address(temp, code_offset.SizeValue())); |
| 4088 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4089 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4090 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4091 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4092 | DCHECK(!codegen_->IsLeafMethod()); |
| 4093 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4094 | } |
| 4095 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4096 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 4097 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4098 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4099 | InvokeRuntimeCallingConvention calling_convention; |
| 4100 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4101 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4102 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4103 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4104 | } |
| 4105 | |
| 4106 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 4107 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4108 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 4109 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4110 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4111 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4112 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4113 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4114 | |
| 4115 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4116 | } |
| 4117 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4118 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4119 | LocationSummary* locations = |
| 4120 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4121 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4122 | if (location.IsStackSlot()) { |
| 4123 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4124 | } else if (location.IsDoubleStackSlot()) { |
| 4125 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4126 | } |
| 4127 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4128 | } |
| 4129 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4130 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4131 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4132 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4136 | LocationSummary* locations = |
| 4137 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4138 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4139 | } |
| 4140 | |
| 4141 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4142 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4143 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4144 | } |
| 4145 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4146 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4147 | LocationSummary* locations = |
| 4148 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4149 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4150 | locations->SetOut(Location::RequiresRegister()); |
| 4151 | } |
| 4152 | |
| 4153 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4154 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4155 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4156 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4157 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4158 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4159 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4160 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4161 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4162 | instruction->GetIndex(), kX86_64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4163 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4164 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4165 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4166 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4167 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4168 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4169 | } |
| 4170 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4171 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4172 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4173 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4174 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4175 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4176 | } |
| 4177 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4178 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4179 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4180 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4181 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4182 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4183 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4184 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4185 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4186 | break; |
| 4187 | |
| 4188 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4189 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4190 | break; |
| 4191 | |
| 4192 | default: |
| 4193 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4194 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4195 | } |
| 4196 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4197 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4198 | LocationSummary* locations = |
| 4199 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4200 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4201 | locations->SetOut(Location::SameAsFirstInput()); |
| 4202 | } |
| 4203 | |
| 4204 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4205 | LocationSummary* locations = bool_not->GetLocations(); |
| 4206 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4207 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4208 | Location out = locations->Out(); |
| 4209 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4210 | } |
| 4211 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4212 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4213 | LocationSummary* locations = |
| 4214 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4215 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4216 | locations->SetInAt(i, Location::Any()); |
| 4217 | } |
| 4218 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4219 | } |
| 4220 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4221 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4222 | LOG(FATAL) << "Unimplemented"; |
| 4223 | } |
| 4224 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4225 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4226 | /* |
| 4227 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4228 | * 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] | 4229 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4230 | */ |
| 4231 | switch (kind) { |
| 4232 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4233 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4234 | break; |
| 4235 | } |
| 4236 | case MemBarrierKind::kAnyStore: |
| 4237 | case MemBarrierKind::kLoadAny: |
| 4238 | case MemBarrierKind::kStoreStore: { |
| 4239 | // nop |
| 4240 | break; |
| 4241 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4242 | case MemBarrierKind::kNTStoreStore: |
| 4243 | // Non-Temporal Store/Store needs an explicit fence. |
| 4244 | MemoryFence(/* non-temporal */ true); |
| 4245 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4246 | } |
| 4247 | } |
| 4248 | |
| 4249 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4250 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4251 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4252 | bool object_field_get_with_read_barrier = |
| 4253 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4254 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4255 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4256 | object_field_get_with_read_barrier ? |
| 4257 | LocationSummary::kCallOnSlowPath : |
| 4258 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4259 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4260 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4261 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4262 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4263 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4264 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4265 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4266 | // The output overlaps for an object field get when read barriers |
| 4267 | // are enabled: we do not want the move to overwrite the object's |
| 4268 | // location, as we need it to emit the read barrier. |
| 4269 | locations->SetOut( |
| 4270 | Location::RequiresRegister(), |
| 4271 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4272 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4273 | } |
| 4274 | |
| 4275 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4276 | const FieldInfo& field_info) { |
| 4277 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4278 | |
| 4279 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4280 | Location base_loc = locations->InAt(0); |
| 4281 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4282 | Location out = locations->Out(); |
| 4283 | bool is_volatile = field_info.IsVolatile(); |
| 4284 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4285 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4286 | |
| 4287 | switch (field_type) { |
| 4288 | case Primitive::kPrimBoolean: { |
| 4289 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4290 | break; |
| 4291 | } |
| 4292 | |
| 4293 | case Primitive::kPrimByte: { |
| 4294 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4295 | break; |
| 4296 | } |
| 4297 | |
| 4298 | case Primitive::kPrimShort: { |
| 4299 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4300 | break; |
| 4301 | } |
| 4302 | |
| 4303 | case Primitive::kPrimChar: { |
| 4304 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4305 | break; |
| 4306 | } |
| 4307 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4308 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4309 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4310 | break; |
| 4311 | } |
| 4312 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4313 | case Primitive::kPrimNot: { |
| 4314 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4315 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4316 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4317 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4318 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4319 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4320 | if (is_volatile) { |
| 4321 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4322 | } |
| 4323 | } else { |
| 4324 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4325 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4326 | if (is_volatile) { |
| 4327 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4328 | } |
| 4329 | // If read barriers are enabled, emit read barriers other than |
| 4330 | // Baker's using a slow path (and also unpoison the loaded |
| 4331 | // reference, if heap poisoning is enabled). |
| 4332 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4333 | } |
| 4334 | break; |
| 4335 | } |
| 4336 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4337 | case Primitive::kPrimLong: { |
| 4338 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4339 | break; |
| 4340 | } |
| 4341 | |
| 4342 | case Primitive::kPrimFloat: { |
| 4343 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4344 | break; |
| 4345 | } |
| 4346 | |
| 4347 | case Primitive::kPrimDouble: { |
| 4348 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4349 | break; |
| 4350 | } |
| 4351 | |
| 4352 | case Primitive::kPrimVoid: |
| 4353 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4354 | UNREACHABLE(); |
| 4355 | } |
| 4356 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4357 | if (field_type == Primitive::kPrimNot) { |
| 4358 | // Potential implicit null checks, in the case of reference |
| 4359 | // fields, are handled in the previous switch statement. |
| 4360 | } else { |
| 4361 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4362 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4363 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4364 | if (is_volatile) { |
| 4365 | if (field_type == Primitive::kPrimNot) { |
| 4366 | // Memory barriers, in the case of references, are also handled |
| 4367 | // in the previous switch statement. |
| 4368 | } else { |
| 4369 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4370 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4371 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4372 | } |
| 4373 | |
| 4374 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4375 | const FieldInfo& field_info) { |
| 4376 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4377 | |
| 4378 | LocationSummary* locations = |
| 4379 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4380 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4381 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4382 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4383 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4384 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4385 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4386 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4387 | if (is_volatile) { |
| 4388 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4389 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4390 | } else { |
| 4391 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4392 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4393 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4394 | if (is_volatile) { |
| 4395 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4396 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4397 | } else { |
| 4398 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4399 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4400 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4401 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4402 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4403 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4404 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4405 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4406 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4407 | locations->AddTemp(Location::RequiresRegister()); |
| 4408 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4409 | } |
| 4410 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4411 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4412 | const FieldInfo& field_info, |
| 4413 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4414 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4415 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4416 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4417 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4418 | Location value = locations->InAt(1); |
| 4419 | bool is_volatile = field_info.IsVolatile(); |
| 4420 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4421 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4422 | |
| 4423 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4424 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4425 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4426 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4427 | bool maybe_record_implicit_null_check_done = false; |
| 4428 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4429 | switch (field_type) { |
| 4430 | case Primitive::kPrimBoolean: |
| 4431 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4432 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4433 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4434 | __ movb(Address(base, offset), Immediate(v)); |
| 4435 | } else { |
| 4436 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4437 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4438 | break; |
| 4439 | } |
| 4440 | |
| 4441 | case Primitive::kPrimShort: |
| 4442 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4443 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4444 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4445 | __ movw(Address(base, offset), Immediate(v)); |
| 4446 | } else { |
| 4447 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4448 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4449 | break; |
| 4450 | } |
| 4451 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4452 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4453 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4454 | if (value.IsConstant()) { |
| 4455 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4456 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4457 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4458 | // Note: if heap poisoning is enabled, no need to poison |
| 4459 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4460 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4461 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4462 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4463 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4464 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4465 | __ PoisonHeapReference(temp); |
| 4466 | __ movl(Address(base, offset), temp); |
| 4467 | } else { |
| 4468 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4469 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4470 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4471 | break; |
| 4472 | } |
| 4473 | |
| 4474 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4475 | if (value.IsConstant()) { |
| 4476 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4477 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4478 | Address(base, offset + sizeof(int32_t)), |
| 4479 | v, |
| 4480 | instruction); |
| 4481 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4482 | } else { |
| 4483 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4484 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4485 | break; |
| 4486 | } |
| 4487 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4488 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4489 | if (value.IsConstant()) { |
| 4490 | int32_t v = |
| 4491 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4492 | __ movl(Address(base, offset), Immediate(v)); |
| 4493 | } else { |
| 4494 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4495 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4496 | break; |
| 4497 | } |
| 4498 | |
| 4499 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4500 | if (value.IsConstant()) { |
| 4501 | int64_t v = |
| 4502 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4503 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4504 | Address(base, offset + sizeof(int32_t)), |
| 4505 | v, |
| 4506 | instruction); |
| 4507 | maybe_record_implicit_null_check_done = true; |
| 4508 | } else { |
| 4509 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4510 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4511 | break; |
| 4512 | } |
| 4513 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4514 | case Primitive::kPrimVoid: |
| 4515 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4516 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4517 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4518 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4519 | if (!maybe_record_implicit_null_check_done) { |
| 4520 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4521 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4522 | |
| 4523 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4524 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4525 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4526 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4527 | } |
| 4528 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4529 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4530 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4531 | } |
| 4532 | } |
| 4533 | |
| 4534 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4535 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4536 | } |
| 4537 | |
| 4538 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4539 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4540 | } |
| 4541 | |
| 4542 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4543 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4544 | } |
| 4545 | |
| 4546 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4547 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4548 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4549 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4550 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4551 | HandleFieldGet(instruction); |
| 4552 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4553 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4554 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4555 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4556 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4557 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4558 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4559 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4560 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4561 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4562 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4563 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4564 | } |
| 4565 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4566 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4567 | HUnresolvedInstanceFieldGet* instruction) { |
| 4568 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4569 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4570 | instruction, instruction->GetFieldType(), calling_convention); |
| 4571 | } |
| 4572 | |
| 4573 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4574 | HUnresolvedInstanceFieldGet* instruction) { |
| 4575 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4576 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4577 | instruction->GetFieldType(), |
| 4578 | instruction->GetFieldIndex(), |
| 4579 | instruction->GetDexPc(), |
| 4580 | calling_convention); |
| 4581 | } |
| 4582 | |
| 4583 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4584 | HUnresolvedInstanceFieldSet* instruction) { |
| 4585 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4586 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4587 | instruction, instruction->GetFieldType(), calling_convention); |
| 4588 | } |
| 4589 | |
| 4590 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4591 | HUnresolvedInstanceFieldSet* instruction) { |
| 4592 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4593 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4594 | instruction->GetFieldType(), |
| 4595 | instruction->GetFieldIndex(), |
| 4596 | instruction->GetDexPc(), |
| 4597 | calling_convention); |
| 4598 | } |
| 4599 | |
| 4600 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4601 | HUnresolvedStaticFieldGet* instruction) { |
| 4602 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4603 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4604 | instruction, instruction->GetFieldType(), calling_convention); |
| 4605 | } |
| 4606 | |
| 4607 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4608 | HUnresolvedStaticFieldGet* instruction) { |
| 4609 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4610 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4611 | instruction->GetFieldType(), |
| 4612 | instruction->GetFieldIndex(), |
| 4613 | instruction->GetDexPc(), |
| 4614 | calling_convention); |
| 4615 | } |
| 4616 | |
| 4617 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4618 | HUnresolvedStaticFieldSet* instruction) { |
| 4619 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4620 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4621 | instruction, instruction->GetFieldType(), calling_convention); |
| 4622 | } |
| 4623 | |
| 4624 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4625 | HUnresolvedStaticFieldSet* instruction) { |
| 4626 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4627 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4628 | instruction->GetFieldType(), |
| 4629 | instruction->GetFieldIndex(), |
| 4630 | instruction->GetDexPc(), |
| 4631 | calling_convention); |
| 4632 | } |
| 4633 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4634 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4635 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4636 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4637 | ? Location::RequiresRegister() |
| 4638 | : Location::Any(); |
| 4639 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4640 | } |
| 4641 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4642 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4643 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4644 | return; |
| 4645 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4646 | LocationSummary* locations = instruction->GetLocations(); |
| 4647 | Location obj = locations->InAt(0); |
| 4648 | |
| 4649 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4650 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4651 | } |
| 4652 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4653 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4654 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4655 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4656 | |
| 4657 | LocationSummary* locations = instruction->GetLocations(); |
| 4658 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4659 | |
| 4660 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4661 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4662 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4663 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4664 | } else { |
| 4665 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4666 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4667 | __ jmp(slow_path->GetEntryLabel()); |
| 4668 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4669 | } |
| 4670 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4671 | } |
| 4672 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4673 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4674 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4675 | } |
| 4676 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4677 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4678 | bool object_array_get_with_read_barrier = |
| 4679 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4680 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4681 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4682 | object_array_get_with_read_barrier ? |
| 4683 | LocationSummary::kCallOnSlowPath : |
| 4684 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4685 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4686 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4687 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4688 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4689 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4690 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4691 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4692 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4693 | // The output overlaps for an object array get when read barriers |
| 4694 | // are enabled: we do not want the move to overwrite the array's |
| 4695 | // location, as we need it to emit the read barrier. |
| 4696 | locations->SetOut( |
| 4697 | Location::RequiresRegister(), |
| 4698 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4699 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4703 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4704 | Location obj_loc = locations->InAt(0); |
| 4705 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4706 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4707 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4708 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4709 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4710 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4711 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4712 | case Primitive::kPrimBoolean: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4713 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4714 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4715 | break; |
| 4716 | } |
| 4717 | |
| 4718 | case Primitive::kPrimByte: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4719 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4720 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4721 | break; |
| 4722 | } |
| 4723 | |
| 4724 | case Primitive::kPrimShort: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4725 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4726 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4727 | break; |
| 4728 | } |
| 4729 | |
| 4730 | case Primitive::kPrimChar: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4731 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4732 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 4733 | // Branch cases into compressed and uncompressed for each index's type. |
| 4734 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4735 | NearLabel done, not_compressed; |
| 4736 | __ cmpl(Address(obj, count_offset), Immediate(0)); |
| 4737 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4738 | __ j(kGreaterEqual, ¬_compressed); |
| 4739 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 4740 | __ jmp(&done); |
| 4741 | __ Bind(¬_compressed); |
| 4742 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4743 | __ Bind(&done); |
| 4744 | } else { |
| 4745 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4746 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4747 | break; |
| 4748 | } |
| 4749 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4750 | case Primitive::kPrimInt: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4751 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4752 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4753 | break; |
| 4754 | } |
| 4755 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4756 | case Primitive::kPrimNot: { |
| 4757 | static_assert( |
| 4758 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4759 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4760 | // /* HeapReference<Object> */ out = |
| 4761 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4762 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4763 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4764 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4765 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4766 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4767 | } else { |
| 4768 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4769 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 4770 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4771 | // If read barriers are enabled, emit read barriers other than |
| 4772 | // Baker's using a slow path (and also unpoison the loaded |
| 4773 | // reference, if heap poisoning is enabled). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4774 | if (index.IsConstant()) { |
| 4775 | uint32_t offset = |
| 4776 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4777 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4778 | } else { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4779 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4780 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4781 | } |
| 4782 | } |
| 4783 | break; |
| 4784 | } |
| 4785 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4786 | case Primitive::kPrimLong: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4787 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4788 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4789 | break; |
| 4790 | } |
| 4791 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4792 | case Primitive::kPrimFloat: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4793 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4794 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4795 | break; |
| 4796 | } |
| 4797 | |
| 4798 | case Primitive::kPrimDouble: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4799 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4800 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4801 | break; |
| 4802 | } |
| 4803 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4804 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4805 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4806 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4807 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4808 | |
| 4809 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4810 | // Potential implicit null checks, in the case of reference |
| 4811 | // arrays, are handled in the previous switch statement. |
| 4812 | } else { |
| 4813 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4814 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4818 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4819 | |
| 4820 | bool needs_write_barrier = |
| 4821 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4822 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4823 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4824 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4825 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4826 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4827 | LocationSummary::kCallOnSlowPath : |
| 4828 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4829 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4830 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4831 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4832 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4833 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4834 | } else { |
| 4835 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4836 | } |
| 4837 | |
| 4838 | if (needs_write_barrier) { |
| 4839 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4840 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4841 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4842 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4846 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4847 | Location array_loc = locations->InAt(0); |
| 4848 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4849 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4850 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4851 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4852 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4853 | bool needs_write_barrier = |
| 4854 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4855 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4856 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4857 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4858 | |
| 4859 | switch (value_type) { |
| 4860 | case Primitive::kPrimBoolean: |
| 4861 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4862 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4863 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4864 | if (value.IsRegister()) { |
| 4865 | __ movb(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 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4868 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4869 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4870 | break; |
| 4871 | } |
| 4872 | |
| 4873 | case Primitive::kPrimShort: |
| 4874 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4875 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4876 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4877 | if (value.IsRegister()) { |
| 4878 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4879 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4880 | DCHECK(value.IsConstant()) << value; |
| 4881 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4882 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4883 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4884 | break; |
| 4885 | } |
| 4886 | |
| 4887 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4888 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4889 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4890 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4891 | if (!value.IsRegister()) { |
| 4892 | // Just setting null. |
| 4893 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4894 | DCHECK(value.IsConstant()) << value; |
| 4895 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4896 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4897 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4898 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4899 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4900 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4901 | |
| 4902 | DCHECK(needs_write_barrier); |
| 4903 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4904 | // We cannot use a NearLabel for `done`, as its range may be too |
| 4905 | // short when Baker read barriers are enabled. |
| 4906 | Label done; |
| 4907 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4908 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4909 | Location temp_loc = locations->GetTemp(0); |
| 4910 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4911 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4912 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4913 | codegen_->AddSlowPath(slow_path); |
| 4914 | if (instruction->GetValueCanBeNull()) { |
| 4915 | __ testl(register_value, register_value); |
| 4916 | __ j(kNotEqual, ¬_null); |
| 4917 | __ movl(address, Immediate(0)); |
| 4918 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4919 | __ jmp(&done); |
| 4920 | __ Bind(¬_null); |
| 4921 | } |
| 4922 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4923 | // Note that when Baker read barriers are enabled, the type |
| 4924 | // checks are performed without read barriers. This is fine, |
| 4925 | // even in the case where a class object is in the from-space |
| 4926 | // after the flip, as a comparison involving such a type would |
| 4927 | // not produce a false positive; it may of course produce a |
| 4928 | // false negative, in which case we would take the ArraySet |
| 4929 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4930 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4931 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4932 | __ movl(temp, Address(array, class_offset)); |
| 4933 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4934 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4935 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4936 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4937 | __ movl(temp, Address(temp, component_offset)); |
| 4938 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4939 | // nor the object reference in `register_value->klass`, as |
| 4940 | // we are comparing two poisoned references. |
| 4941 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4942 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4943 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4944 | __ j(kEqual, &do_put); |
| 4945 | // If heap poisoning is enabled, the `temp` reference has |
| 4946 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4947 | __ MaybeUnpoisonHeapReference(temp); |
| 4948 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4949 | // If heap poisoning is enabled, no need to unpoison the |
| 4950 | // heap reference loaded below, as it is only used for a |
| 4951 | // comparison with null. |
| 4952 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 4953 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4954 | __ Bind(&do_put); |
| 4955 | } else { |
| 4956 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4957 | } |
| 4958 | } |
| 4959 | |
| 4960 | if (kPoisonHeapReferences) { |
| 4961 | __ movl(temp, register_value); |
| 4962 | __ PoisonHeapReference(temp); |
| 4963 | __ movl(address, temp); |
| 4964 | } else { |
| 4965 | __ movl(address, register_value); |
| 4966 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4967 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4968 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4969 | } |
| 4970 | |
| 4971 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4972 | codegen_->MarkGCCard( |
| 4973 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4974 | __ Bind(&done); |
| 4975 | |
| 4976 | if (slow_path != nullptr) { |
| 4977 | __ Bind(slow_path->GetExitLabel()); |
| 4978 | } |
| 4979 | |
| 4980 | break; |
| 4981 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4982 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4983 | case Primitive::kPrimInt: { |
| 4984 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4985 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4986 | if (value.IsRegister()) { |
| 4987 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4988 | } else { |
| 4989 | DCHECK(value.IsConstant()) << value; |
| 4990 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4991 | __ movl(address, Immediate(v)); |
| 4992 | } |
| 4993 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4994 | break; |
| 4995 | } |
| 4996 | |
| 4997 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4998 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4999 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5000 | if (value.IsRegister()) { |
| 5001 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5002 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5003 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5004 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5005 | Address address_high = |
| 5006 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5007 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5008 | } |
| 5009 | break; |
| 5010 | } |
| 5011 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5012 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5013 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5014 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5015 | if (value.IsFpuRegister()) { |
| 5016 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5017 | } else { |
| 5018 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5019 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5020 | __ movl(address, Immediate(v)); |
| 5021 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5022 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5023 | break; |
| 5024 | } |
| 5025 | |
| 5026 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5027 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5028 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5029 | if (value.IsFpuRegister()) { |
| 5030 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5031 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5032 | } else { |
| 5033 | int64_t v = |
| 5034 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5035 | Address address_high = |
| 5036 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5037 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5038 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5039 | break; |
| 5040 | } |
| 5041 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5042 | case Primitive::kPrimVoid: |
| 5043 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5044 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5045 | } |
| 5046 | } |
| 5047 | |
| 5048 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5049 | LocationSummary* locations = |
| 5050 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5051 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5052 | if (!instruction->IsEmittedAtUseSite()) { |
| 5053 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5054 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5055 | } |
| 5056 | |
| 5057 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5058 | if (instruction->IsEmittedAtUseSite()) { |
| 5059 | return; |
| 5060 | } |
| 5061 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5062 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5063 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5064 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5065 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5066 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5067 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5068 | // Mask out most significant bit in case the array is String's array of char. |
| 5069 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 5070 | __ andl(out, Immediate(INT32_MAX)); |
| 5071 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5075 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5076 | InvokeRuntimeCallingConvention calling_convention; |
| 5077 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5078 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5079 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5080 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5081 | HInstruction* length = instruction->InputAt(1); |
| 5082 | if (!length->IsEmittedAtUseSite()) { |
| 5083 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5084 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5085 | } |
| 5086 | |
| 5087 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5088 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5089 | Location index_loc = locations->InAt(0); |
| 5090 | Location length_loc = locations->InAt(1); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5091 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5092 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5093 | if (length_loc.IsConstant()) { |
| 5094 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5095 | if (index_loc.IsConstant()) { |
| 5096 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5097 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5098 | if (index < 0 || index >= length) { |
| 5099 | codegen_->AddSlowPath(slow_path); |
| 5100 | __ jmp(slow_path->GetEntryLabel()); |
| 5101 | } else { |
| 5102 | // Some optimization after BCE may have generated this, and we should not |
| 5103 | // generate a bounds check if it is a valid range. |
| 5104 | } |
| 5105 | return; |
| 5106 | } |
| 5107 | |
| 5108 | // We have to reverse the jump condition because the length is the constant. |
| 5109 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5110 | __ cmpl(index_reg, Immediate(length)); |
| 5111 | codegen_->AddSlowPath(slow_path); |
| 5112 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5113 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5114 | HInstruction* array_length = instruction->InputAt(1); |
| 5115 | if (array_length->IsEmittedAtUseSite()) { |
| 5116 | // Address the length field in the array. |
| 5117 | DCHECK(array_length->IsArrayLength()); |
| 5118 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5119 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5120 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5121 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5122 | CpuRegister length_reg = CpuRegister(TMP); |
| 5123 | __ movl(length_reg, array_len); |
| 5124 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| 5125 | __ andl(length_reg, Immediate(INT32_MAX)); |
| 5126 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5127 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5128 | // Checking the bound for general case: |
| 5129 | // Array of char or String's array when the compression feature off. |
| 5130 | if (index_loc.IsConstant()) { |
| 5131 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5132 | __ cmpl(array_len, Immediate(value)); |
| 5133 | } else { |
| 5134 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5135 | } |
| 5136 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5137 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5138 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5139 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5140 | } |
| 5141 | codegen_->AddSlowPath(slow_path); |
| 5142 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5143 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5147 | CpuRegister card, |
| 5148 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5149 | CpuRegister value, |
| 5150 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5151 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5152 | if (value_can_be_null) { |
| 5153 | __ testl(value, value); |
| 5154 | __ j(kEqual, &is_null); |
| 5155 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5156 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5157 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5158 | __ movq(temp, object); |
| 5159 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5160 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5161 | if (value_can_be_null) { |
| 5162 | __ Bind(&is_null); |
| 5163 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5164 | } |
| 5165 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5166 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5167 | LOG(FATAL) << "Unimplemented"; |
| 5168 | } |
| 5169 | |
| 5170 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5171 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5172 | } |
| 5173 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5174 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5175 | LocationSummary* locations = |
| 5176 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5177 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5178 | } |
| 5179 | |
| 5180 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5181 | HBasicBlock* block = instruction->GetBlock(); |
| 5182 | if (block->GetLoopInformation() != nullptr) { |
| 5183 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5184 | // The back edge will generate the suspend check. |
| 5185 | return; |
| 5186 | } |
| 5187 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5188 | // The goto will generate the suspend check. |
| 5189 | return; |
| 5190 | } |
| 5191 | GenerateSuspendCheck(instruction, nullptr); |
| 5192 | } |
| 5193 | |
| 5194 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5195 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5196 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5197 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5198 | if (slow_path == nullptr) { |
| 5199 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5200 | instruction->SetSlowPath(slow_path); |
| 5201 | codegen_->AddSlowPath(slow_path); |
| 5202 | if (successor != nullptr) { |
| 5203 | DCHECK(successor->IsLoopHeader()); |
| 5204 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5205 | } |
| 5206 | } else { |
| 5207 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5208 | } |
| 5209 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5210 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5211 | /* no_rip */ true), |
| 5212 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5213 | if (successor == nullptr) { |
| 5214 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5215 | __ Bind(slow_path->GetReturnLabel()); |
| 5216 | } else { |
| 5217 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5218 | __ jmp(slow_path->GetEntryLabel()); |
| 5219 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5220 | } |
| 5221 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5222 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5223 | return codegen_->GetAssembler(); |
| 5224 | } |
| 5225 | |
| 5226 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5227 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5228 | Location source = move->GetSource(); |
| 5229 | Location destination = move->GetDestination(); |
| 5230 | |
| 5231 | if (source.IsRegister()) { |
| 5232 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5233 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5234 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5235 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5236 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5237 | } else { |
| 5238 | DCHECK(destination.IsDoubleStackSlot()); |
| 5239 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5240 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5241 | } |
| 5242 | } else if (source.IsStackSlot()) { |
| 5243 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5244 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5245 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5246 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5247 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5248 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5249 | } else { |
| 5250 | DCHECK(destination.IsStackSlot()); |
| 5251 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5252 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5253 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5254 | } else if (source.IsDoubleStackSlot()) { |
| 5255 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5256 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5257 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5258 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5259 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5260 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5261 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5262 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5263 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5264 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5265 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5266 | } else if (source.IsConstant()) { |
| 5267 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5268 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5269 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5270 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5271 | if (value == 0) { |
| 5272 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5273 | } else { |
| 5274 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5275 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5276 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5277 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5278 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5279 | } |
| 5280 | } else if (constant->IsLongConstant()) { |
| 5281 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5282 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5283 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5284 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5285 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5286 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5287 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5288 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5289 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5290 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5291 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5292 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5293 | } else { |
| 5294 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5295 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5296 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5297 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5298 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5299 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5300 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5301 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5302 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5303 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5304 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5305 | } else { |
| 5306 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5307 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5308 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5309 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5310 | } else if (source.IsFpuRegister()) { |
| 5311 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5312 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5313 | } else if (destination.IsStackSlot()) { |
| 5314 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5315 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5316 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5317 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5318 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 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) { |
| 5438 | case HLoadClass::LoadKind::kReferrersClass: |
| 5439 | break; |
| 5440 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5441 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5442 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5443 | return HLoadClass::LoadKind::kBootImageLinkTimePcRelative; |
| 5444 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5445 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5446 | break; |
| 5447 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5448 | break; |
| 5449 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5450 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5451 | break; |
| 5452 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5453 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5454 | break; |
| 5455 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5456 | break; |
| 5457 | } |
| 5458 | return desired_class_load_kind; |
| 5459 | } |
| 5460 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5461 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5462 | if (cls->NeedsAccessCheck()) { |
| 5463 | InvokeRuntimeCallingConvention calling_convention; |
| 5464 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5465 | cls, |
| 5466 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5467 | Location::RegisterLocation(RAX), |
| 5468 | /* code_generator_supports_read_barrier */ true); |
| 5469 | return; |
| 5470 | } |
| 5471 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5472 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5473 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5474 | ? LocationSummary::kCallOnSlowPath |
| 5475 | : LocationSummary::kNoCall; |
| 5476 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5477 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5478 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5479 | } |
| 5480 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5481 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5482 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5483 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5484 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5485 | } |
| 5486 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5487 | } |
| 5488 | |
| 5489 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5490 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5491 | if (cls->NeedsAccessCheck()) { |
| 5492 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5493 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5494 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5495 | return; |
| 5496 | } |
| 5497 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5498 | Location out_loc = locations->Out(); |
| 5499 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5500 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5501 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5502 | bool generate_null_check = false; |
| 5503 | switch (cls->GetLoadKind()) { |
| 5504 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5505 | DCHECK(!cls->CanCallRuntime()); |
| 5506 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5507 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5508 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5509 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5510 | cls, |
| 5511 | out_loc, |
| 5512 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5513 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5514 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5515 | break; |
| 5516 | } |
| 5517 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5518 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5519 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5520 | codegen_->RecordTypePatch(cls); |
| 5521 | break; |
| 5522 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5523 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5524 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5525 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5526 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5527 | codegen_->RecordSimplePatch(); |
| 5528 | break; |
| 5529 | } |
| 5530 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5531 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5532 | // /* GcRoot<mirror::Class> */ out = *address |
| 5533 | if (IsUint<32>(cls->GetAddress())) { |
| 5534 | Address address = Address::Absolute(cls->GetAddress(), /* no_rip */ true); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5535 | GenerateGcRootFieldLoad(cls, |
| 5536 | out_loc, |
| 5537 | address, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5538 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5539 | requires_read_barrier); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5540 | } else { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5541 | // TODO: Consider using opcode A1, i.e. movl eax, moff32 (with 64-bit address). |
| 5542 | __ movq(out, Immediate(cls->GetAddress())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5543 | GenerateGcRootFieldLoad(cls, |
| 5544 | out_loc, |
| 5545 | Address(out, 0), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5546 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5547 | requires_read_barrier); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5548 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5549 | generate_null_check = !cls->IsInDexCache(); |
| 5550 | break; |
| 5551 | } |
| 5552 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5553 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 5554 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 5555 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5556 | /* no_rip */ false); |
| 5557 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5558 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5559 | generate_null_check = !cls->IsInDexCache(); |
| 5560 | break; |
| 5561 | } |
| 5562 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5563 | // /* GcRoot<mirror::Class>[] */ out = |
| 5564 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5565 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5566 | __ movq(out, |
| 5567 | Address(current_method, |
| 5568 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
| 5569 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5570 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5571 | cls, |
| 5572 | out_loc, |
| 5573 | Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5574 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5575 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5576 | generate_null_check = !cls->IsInDexCache(); |
| 5577 | break; |
| 5578 | } |
| 5579 | default: |
| 5580 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5581 | UNREACHABLE(); |
| 5582 | } |
| 5583 | |
| 5584 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5585 | DCHECK(cls->CanCallRuntime()); |
| 5586 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5587 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5588 | codegen_->AddSlowPath(slow_path); |
| 5589 | if (generate_null_check) { |
| 5590 | __ testl(out, out); |
| 5591 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5592 | } |
| 5593 | if (cls->MustGenerateClinitCheck()) { |
| 5594 | GenerateClassInitializationCheck(slow_path, out); |
| 5595 | } else { |
| 5596 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5597 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5598 | } |
| 5599 | } |
| 5600 | |
| 5601 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5602 | LocationSummary* locations = |
| 5603 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5604 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5605 | if (check->HasUses()) { |
| 5606 | locations->SetOut(Location::SameAsFirstInput()); |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5611 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5612 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5613 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5614 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5615 | GenerateClassInitializationCheck(slow_path, |
| 5616 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5617 | } |
| 5618 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5619 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5620 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5621 | switch (desired_string_load_kind) { |
| 5622 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5623 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5624 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5625 | return HLoadString::LoadKind::kBootImageLinkTimePcRelative; |
| 5626 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5627 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5628 | break; |
| 5629 | case HLoadString::LoadKind::kBootImageAddress: |
| 5630 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5631 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5632 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5633 | break; |
| 5634 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5635 | break; |
Nicolas Geoffray | ac3ebc3 | 2016-10-05 13:13:50 +0100 | [diff] [blame] | 5636 | case HLoadString::LoadKind::kJitTableAddress: |
| 5637 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5638 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5639 | } |
| 5640 | return desired_string_load_kind; |
| 5641 | } |
| 5642 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5643 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5644 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5645 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 5646 | ? LocationSummary::kCallOnMainOnly |
| 5647 | : LocationSummary::kCallOnSlowPath) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5648 | : LocationSummary::kNoCall; |
| 5649 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5650 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5651 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 5652 | } else { |
| 5653 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5654 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5655 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5656 | // Rely on the pResolveString and/or marking to save everything. |
| 5657 | // Custom calling convention: RAX serves as both input and output. |
| 5658 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5659 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5660 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5661 | } else { |
| 5662 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5663 | } |
| 5664 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5665 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5666 | } |
| 5667 | |
Nicolas Geoffray | ac3ebc3 | 2016-10-05 13:13:50 +0100 | [diff] [blame] | 5668 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, uint32_t dex_index) { |
| 5669 | jit_string_roots_.Overwrite(StringReference(&dex_file, dex_index), /* placeholder */ 0u); |
| 5670 | // Add a patch entry and return the label. |
| 5671 | jit_string_patches_.emplace_back(dex_file, dex_index); |
| 5672 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 5673 | return &info->label; |
| 5674 | } |
| 5675 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5676 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5677 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5678 | Location out_loc = locations->Out(); |
| 5679 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5680 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5681 | switch (load->GetLoadKind()) { |
| 5682 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
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: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5688 | DCHECK_NE(load->GetAddress(), 0u); |
| 5689 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5690 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5691 | codegen_->RecordSimplePatch(); |
| 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 */ |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5699 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kEmitCompilerReadBarrier); |
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 | ac3ebc3 | 2016-10-05 13:13:50 +0100 | [diff] [blame] | 5707 | case HLoadString::LoadKind::kJitTableAddress: { |
| 5708 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5709 | /* no_rip */ true); |
| 5710 | Label* fixup_label = |
| 5711 | codegen_->NewJitRootStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| 5712 | // /* GcRoot<mirror::String> */ out = *address |
| 5713 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kEmitCompilerReadBarrier); |
| 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. |
| 5722 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex())); |
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 | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5844 | // /* HeapReference<Class> */ out = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 5845 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5846 | out_loc, |
| 5847 | obj_loc, |
| 5848 | class_offset, |
| 5849 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5850 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5851 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5852 | case TypeCheckKind::kExactCheck: { |
| 5853 | if (cls.IsRegister()) { |
| 5854 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5855 | } else { |
| 5856 | DCHECK(cls.IsStackSlot()) << cls; |
| 5857 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5858 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5859 | if (zero.IsLinked()) { |
| 5860 | // Classes must be equal for the instanceof to succeed. |
| 5861 | __ j(kNotEqual, &zero); |
| 5862 | __ movl(out, Immediate(1)); |
| 5863 | __ jmp(&done); |
| 5864 | } else { |
| 5865 | __ setcc(kEqual, out); |
| 5866 | // setcc only sets the low byte. |
| 5867 | __ andl(out, Immediate(1)); |
| 5868 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5869 | break; |
| 5870 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5871 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5872 | case TypeCheckKind::kAbstractClassCheck: { |
| 5873 | // If the class is abstract, we eagerly fetch the super class of the |
| 5874 | // object to avoid doing a comparison we know will fail. |
| 5875 | NearLabel loop, success; |
| 5876 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5877 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5878 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5879 | __ testl(out, out); |
| 5880 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5881 | __ j(kEqual, &done); |
| 5882 | if (cls.IsRegister()) { |
| 5883 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5884 | } else { |
| 5885 | DCHECK(cls.IsStackSlot()) << cls; |
| 5886 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5887 | } |
| 5888 | __ j(kNotEqual, &loop); |
| 5889 | __ movl(out, Immediate(1)); |
| 5890 | if (zero.IsLinked()) { |
| 5891 | __ jmp(&done); |
| 5892 | } |
| 5893 | break; |
| 5894 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5895 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5896 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5897 | // Walk over the class hierarchy to find a match. |
| 5898 | NearLabel loop, success; |
| 5899 | __ Bind(&loop); |
| 5900 | if (cls.IsRegister()) { |
| 5901 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5902 | } else { |
| 5903 | DCHECK(cls.IsStackSlot()) << cls; |
| 5904 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5905 | } |
| 5906 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5907 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5908 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5909 | __ testl(out, out); |
| 5910 | __ j(kNotEqual, &loop); |
| 5911 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5912 | __ jmp(&done); |
| 5913 | __ Bind(&success); |
| 5914 | __ movl(out, Immediate(1)); |
| 5915 | if (zero.IsLinked()) { |
| 5916 | __ jmp(&done); |
| 5917 | } |
| 5918 | break; |
| 5919 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5920 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5921 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5922 | // Do an exact check. |
| 5923 | NearLabel exact_check; |
| 5924 | if (cls.IsRegister()) { |
| 5925 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5926 | } else { |
| 5927 | DCHECK(cls.IsStackSlot()) << cls; |
| 5928 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5929 | } |
| 5930 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5931 | // 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] | 5932 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5933 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5934 | __ testl(out, out); |
| 5935 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5936 | __ j(kEqual, &done); |
| 5937 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5938 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5939 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5940 | __ movl(out, Immediate(1)); |
| 5941 | __ jmp(&done); |
| 5942 | break; |
| 5943 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5944 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5945 | case TypeCheckKind::kArrayCheck: { |
| 5946 | if (cls.IsRegister()) { |
| 5947 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5948 | } else { |
| 5949 | DCHECK(cls.IsStackSlot()) << cls; |
| 5950 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5951 | } |
| 5952 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5953 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5954 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5955 | codegen_->AddSlowPath(slow_path); |
| 5956 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5957 | __ movl(out, Immediate(1)); |
| 5958 | if (zero.IsLinked()) { |
| 5959 | __ jmp(&done); |
| 5960 | } |
| 5961 | break; |
| 5962 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5963 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5964 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5965 | case TypeCheckKind::kInterfaceCheck: { |
| 5966 | // 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] | 5967 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5968 | // cases. |
| 5969 | // |
| 5970 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5971 | // entry point without resorting to a type checking slow path |
| 5972 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5973 | // require to assign fixed registers for the inputs of this |
| 5974 | // HInstanceOf instruction (following the runtime calling |
| 5975 | // convention), which might be cluttered by the potential first |
| 5976 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5977 | // |
| 5978 | // TODO: Introduce a new runtime entry point taking the object |
| 5979 | // to test (instead of its class) as argument, and let it deal |
| 5980 | // with the read barrier issues. This will let us refactor this |
| 5981 | // case of the `switch` code as it was previously (with a direct |
| 5982 | // call to the runtime not using a type checking slow path). |
| 5983 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5984 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5985 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5986 | /* is_fatal */ false); |
| 5987 | codegen_->AddSlowPath(slow_path); |
| 5988 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5989 | if (zero.IsLinked()) { |
| 5990 | __ jmp(&done); |
| 5991 | } |
| 5992 | break; |
| 5993 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5994 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5995 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5996 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5997 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5998 | __ xorl(out, out); |
| 5999 | } |
| 6000 | |
| 6001 | if (done.IsLinked()) { |
| 6002 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6003 | } |
| 6004 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6005 | if (slow_path != nullptr) { |
| 6006 | __ Bind(slow_path->GetExitLabel()); |
| 6007 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6008 | } |
| 6009 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6010 | static bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6011 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6012 | case TypeCheckKind::kExactCheck: |
| 6013 | case TypeCheckKind::kAbstractClassCheck: |
| 6014 | case TypeCheckKind::kClassHierarchyCheck: |
| 6015 | case TypeCheckKind::kArrayObjectCheck: |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6016 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6017 | case TypeCheckKind::kInterfaceCheck: |
| 6018 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6019 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6020 | case TypeCheckKind::kUnresolvedCheck: |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6021 | return false; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6022 | } |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6023 | LOG(FATAL) << "Unreachable"; |
| 6024 | UNREACHABLE(); |
| 6025 | } |
| 6026 | |
| 6027 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 6028 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6029 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6030 | bool is_fatal_slow_path = IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch); |
| 6031 | LocationSummary::CallKind call_kind = is_fatal_slow_path |
| 6032 | ? LocationSummary::kNoCall |
| 6033 | : LocationSummary::kCallOnSlowPath; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6034 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6035 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6036 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6037 | // Require a register for the interface check since there is a loop that compares the class to |
| 6038 | // a memory address. |
| 6039 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6040 | } else { |
| 6041 | locations->SetInAt(1, Location::Any()); |
| 6042 | } |
| 6043 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6044 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 6045 | locations->AddTemp(Location::RequiresRegister()); |
| 6046 | // When read barriers are enabled, we need an additional temporary |
| 6047 | // register for some cases. |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6048 | if (CheckCastTypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6049 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6050 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6054 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6055 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6056 | Location obj_loc = locations->InAt(0); |
| 6057 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6058 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6059 | Location temp_loc = locations->GetTemp(0); |
| 6060 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6061 | Location maybe_temp2_loc = CheckCastTypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6062 | locations->GetTemp(1) : |
| 6063 | Location::NoLocation(); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6064 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6065 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6066 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6067 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6068 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6069 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6070 | const uint32_t object_array_data_offset = |
| 6071 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6072 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6073 | bool is_type_check_slow_path_fatal = |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6074 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6075 | SlowPathCode* type_check_slow_path = |
| 6076 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6077 | is_type_check_slow_path_fatal); |
| 6078 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6079 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6080 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6081 | case TypeCheckKind::kExactCheck: |
| 6082 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6083 | NearLabel done; |
| 6084 | // Avoid null check if we know obj is not null. |
| 6085 | if (instruction->MustDoNullCheck()) { |
| 6086 | __ testl(obj, obj); |
| 6087 | __ j(kEqual, &done); |
| 6088 | } |
| 6089 | |
| 6090 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6091 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6092 | temp_loc, |
| 6093 | obj_loc, |
| 6094 | class_offset, |
| 6095 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6096 | if (cls.IsRegister()) { |
| 6097 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6098 | } else { |
| 6099 | DCHECK(cls.IsStackSlot()) << cls; |
| 6100 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6101 | } |
| 6102 | // Jump to slow path for throwing the exception or doing a |
| 6103 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6104 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6105 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6106 | break; |
| 6107 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6108 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6109 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6110 | NearLabel done; |
| 6111 | // Avoid null check if we know obj is not null. |
| 6112 | if (instruction->MustDoNullCheck()) { |
| 6113 | __ testl(obj, obj); |
| 6114 | __ j(kEqual, &done); |
| 6115 | } |
| 6116 | |
| 6117 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6118 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6119 | temp_loc, |
| 6120 | obj_loc, |
| 6121 | class_offset, |
| 6122 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6123 | // If the class is abstract, we eagerly fetch the super class of the |
| 6124 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6125 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6126 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6127 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6128 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6129 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6130 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6131 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6132 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6133 | // Otherwise, compare the classes. |
| 6134 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6135 | if (cls.IsRegister()) { |
| 6136 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6137 | } else { |
| 6138 | DCHECK(cls.IsStackSlot()) << cls; |
| 6139 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6140 | } |
| 6141 | __ j(kNotEqual, &loop); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6142 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6143 | break; |
| 6144 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6145 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6146 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6147 | NearLabel done; |
| 6148 | // Avoid null check if we know obj is not null. |
| 6149 | if (instruction->MustDoNullCheck()) { |
| 6150 | __ testl(obj, obj); |
| 6151 | __ j(kEqual, &done); |
| 6152 | } |
| 6153 | |
| 6154 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6155 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6156 | temp_loc, |
| 6157 | obj_loc, |
| 6158 | class_offset, |
| 6159 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6160 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6161 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6162 | __ Bind(&loop); |
| 6163 | if (cls.IsRegister()) { |
| 6164 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6165 | } else { |
| 6166 | DCHECK(cls.IsStackSlot()) << cls; |
| 6167 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6168 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6169 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6170 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6171 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6172 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6173 | |
| 6174 | // If the class reference currently in `temp` is not null, jump |
| 6175 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6176 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6177 | __ j(kNotZero, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6178 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6179 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6180 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6181 | break; |
| 6182 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6183 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6184 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6185 | // We cannot use a NearLabel here, as its range might be too |
| 6186 | // short in some cases when read barriers are enabled. This has |
| 6187 | // been observed for instance when the code emitted for this |
| 6188 | // case uses high x86-64 registers (R8-R15). |
| 6189 | Label done; |
| 6190 | // Avoid null check if we know obj is not null. |
| 6191 | if (instruction->MustDoNullCheck()) { |
| 6192 | __ testl(obj, obj); |
| 6193 | __ j(kEqual, &done); |
| 6194 | } |
| 6195 | |
| 6196 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6197 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6198 | temp_loc, |
| 6199 | obj_loc, |
| 6200 | class_offset, |
| 6201 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6202 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6203 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6204 | if (cls.IsRegister()) { |
| 6205 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6206 | } else { |
| 6207 | DCHECK(cls.IsStackSlot()) << cls; |
| 6208 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6209 | } |
| 6210 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6211 | |
| 6212 | // 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] | 6213 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6214 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6215 | |
| 6216 | // If the component type is not null (i.e. the object is indeed |
| 6217 | // an array), jump to label `check_non_primitive_component_type` |
| 6218 | // to further check that this component type is not a primitive |
| 6219 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6220 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6221 | // Otherwise, jump to the slow path to throw the exception. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6222 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6223 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6224 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6225 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6226 | break; |
| 6227 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6228 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6229 | case TypeCheckKind::kUnresolvedCheck: { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6230 | // 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] | 6231 | // |
| 6232 | // We cannot directly call the CheckCast runtime entry point |
| 6233 | // without resorting to a type checking slow path here (i.e. by |
| 6234 | // calling InvokeRuntime directly), as it would require to |
| 6235 | // assign fixed registers for the inputs of this HInstanceOf |
| 6236 | // instruction (following the runtime calling convention), which |
| 6237 | // might be cluttered by the potential first read barrier |
| 6238 | // emission at the beginning of this method. |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6239 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6240 | NearLabel done; |
| 6241 | // Avoid null check if we know obj is not null. |
| 6242 | if (instruction->MustDoNullCheck()) { |
| 6243 | __ testl(obj, obj); |
| 6244 | __ j(kEqual, &done); |
| 6245 | } |
| 6246 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6247 | __ Bind(&done); |
| 6248 | break; |
| 6249 | } |
| 6250 | |
| 6251 | case TypeCheckKind::kInterfaceCheck: |
| 6252 | NearLabel done; |
| 6253 | |
| 6254 | // Avoid null check if we know obj is not null. |
| 6255 | if (instruction->MustDoNullCheck()) { |
| 6256 | __ testl(obj, obj); |
| 6257 | __ j(kEqual, &done); |
| 6258 | } |
| 6259 | |
| 6260 | // Fast path for the interface check. We always go slow path for heap poisoning since |
| 6261 | // unpoisoning cls would require an extra temp. |
| 6262 | if (!kPoisonHeapReferences) { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6263 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6264 | // doing this. |
| 6265 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6266 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6267 | temp_loc, |
| 6268 | obj_loc, |
| 6269 | class_offset, |
| 6270 | /*emit_read_barrier*/ false); |
| 6271 | |
| 6272 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6273 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6274 | temp_loc, |
| 6275 | temp_loc, |
| 6276 | iftable_offset, |
| 6277 | /*emit_read_barrier*/ false); |
| 6278 | NearLabel is_null; |
| 6279 | // Null iftable means it is empty. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6280 | __ testl(temp, temp); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6281 | __ j(kZero, &is_null); |
| 6282 | |
| 6283 | // Loop through the iftable and check if any class matches. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6284 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6285 | |
| 6286 | NearLabel start_loop; |
| 6287 | __ Bind(&start_loop); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6288 | __ cmpl(cls.AsRegister<CpuRegister>(), Address(temp, object_array_data_offset)); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6289 | __ j(kEqual, &done); // Return if same class. |
| 6290 | // Go to next interface. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame^] | 6291 | __ addl(temp, Immediate(2 * kHeapReferenceSize)); |
| 6292 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6293 | __ j(kNotZero, &start_loop); |
| 6294 | __ Bind(&is_null); |
| 6295 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6296 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6297 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6298 | break; |
| 6299 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6300 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6301 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6302 | } |
| 6303 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6304 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6305 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6306 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6307 | InvokeRuntimeCallingConvention calling_convention; |
| 6308 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6309 | } |
| 6310 | |
| 6311 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6312 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6313 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6314 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6315 | if (instruction->IsEnter()) { |
| 6316 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6317 | } else { |
| 6318 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6319 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6320 | } |
| 6321 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6322 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6323 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6324 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6325 | |
| 6326 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6327 | LocationSummary* locations = |
| 6328 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6329 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6330 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6331 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6332 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6333 | locations->SetOut(Location::SameAsFirstInput()); |
| 6334 | } |
| 6335 | |
| 6336 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6337 | HandleBitwiseOperation(instruction); |
| 6338 | } |
| 6339 | |
| 6340 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6341 | HandleBitwiseOperation(instruction); |
| 6342 | } |
| 6343 | |
| 6344 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6345 | HandleBitwiseOperation(instruction); |
| 6346 | } |
| 6347 | |
| 6348 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6349 | LocationSummary* locations = instruction->GetLocations(); |
| 6350 | Location first = locations->InAt(0); |
| 6351 | Location second = locations->InAt(1); |
| 6352 | DCHECK(first.Equals(locations->Out())); |
| 6353 | |
| 6354 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6355 | if (second.IsRegister()) { |
| 6356 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6357 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6358 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6359 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6360 | } else { |
| 6361 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6362 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6363 | } |
| 6364 | } else if (second.IsConstant()) { |
| 6365 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6366 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6367 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6368 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6369 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6370 | } else { |
| 6371 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6372 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6373 | } |
| 6374 | } else { |
| 6375 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6376 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6377 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6378 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6379 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6380 | } else { |
| 6381 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6382 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6383 | } |
| 6384 | } |
| 6385 | } else { |
| 6386 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6387 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6388 | bool second_is_constant = false; |
| 6389 | int64_t value = 0; |
| 6390 | if (second.IsConstant()) { |
| 6391 | second_is_constant = true; |
| 6392 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6393 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6394 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6395 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6396 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6397 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6398 | if (is_int32_value) { |
| 6399 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6400 | } else { |
| 6401 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6402 | } |
| 6403 | } else if (second.IsDoubleStackSlot()) { |
| 6404 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6405 | } else { |
| 6406 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6407 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6408 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6409 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6410 | if (is_int32_value) { |
| 6411 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6412 | } else { |
| 6413 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6414 | } |
| 6415 | } else if (second.IsDoubleStackSlot()) { |
| 6416 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6417 | } else { |
| 6418 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6419 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6420 | } else { |
| 6421 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6422 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6423 | if (is_int32_value) { |
| 6424 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6425 | } else { |
| 6426 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6427 | } |
| 6428 | } else if (second.IsDoubleStackSlot()) { |
| 6429 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6430 | } else { |
| 6431 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6432 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6433 | } |
| 6434 | } |
| 6435 | } |
| 6436 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6437 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6438 | Location out, |
| 6439 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6440 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6441 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6442 | if (kEmitCompilerReadBarrier) { |
| 6443 | if (kUseBakerReadBarrier) { |
| 6444 | // Load with fast path based Baker's read barrier. |
| 6445 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6446 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6447 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6448 | } else { |
| 6449 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6450 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6451 | // in the following move operation, as we will need it for the |
| 6452 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6453 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6454 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6455 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6456 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6457 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6458 | } |
| 6459 | } else { |
| 6460 | // Plain load with no read barrier. |
| 6461 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6462 | __ movl(out_reg, Address(out_reg, offset)); |
| 6463 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6464 | } |
| 6465 | } |
| 6466 | |
| 6467 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6468 | Location out, |
| 6469 | Location obj, |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6470 | uint32_t offset, |
| 6471 | bool emit_read_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6472 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6473 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6474 | if (emit_read_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6475 | if (kUseBakerReadBarrier) { |
| 6476 | // Load with fast path based Baker's read barrier. |
| 6477 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6478 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6479 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6480 | } else { |
| 6481 | // Load with slow path based read barrier. |
| 6482 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6483 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6484 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6485 | } |
| 6486 | } else { |
| 6487 | // Plain load with no read barrier. |
| 6488 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6489 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6490 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6491 | } |
| 6492 | } |
| 6493 | |
| 6494 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6495 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6496 | const Address& address, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6497 | Label* fixup_label, |
| 6498 | bool requires_read_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6499 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6500 | if (requires_read_barrier) { |
| 6501 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6502 | if (kUseBakerReadBarrier) { |
| 6503 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6504 | // Baker's read barrier are used: |
| 6505 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6506 | // root = *address; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6507 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6508 | // root = ReadBarrier::Mark(root) |
| 6509 | // } |
| 6510 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6511 | // /* GcRoot<mirror::Object> */ root = *address |
| 6512 | __ movl(root_reg, address); |
| 6513 | if (fixup_label != nullptr) { |
| 6514 | __ Bind(fixup_label); |
| 6515 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6516 | static_assert( |
| 6517 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6518 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6519 | "have different sizes."); |
| 6520 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6521 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6522 | "have different sizes."); |
| 6523 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6524 | // Slow path marking the GC root `root`. |
| 6525 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6526 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6527 | codegen_->AddSlowPath(slow_path); |
| 6528 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6529 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6530 | /* no_rip */ true), |
| 6531 | Immediate(0)); |
| 6532 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6533 | __ Bind(slow_path->GetExitLabel()); |
| 6534 | } else { |
| 6535 | // GC root loaded through a slow path for read barriers other |
| 6536 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6537 | // /* GcRoot<mirror::Object>* */ root = address |
| 6538 | __ leaq(root_reg, address); |
| 6539 | if (fixup_label != nullptr) { |
| 6540 | __ Bind(fixup_label); |
| 6541 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6542 | // /* mirror::Object* */ root = root->Read() |
| 6543 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6544 | } |
| 6545 | } else { |
| 6546 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6547 | // /* GcRoot<mirror::Object> */ root = *address |
| 6548 | __ movl(root_reg, address); |
| 6549 | if (fixup_label != nullptr) { |
| 6550 | __ Bind(fixup_label); |
| 6551 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6552 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6553 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6554 | } |
| 6555 | } |
| 6556 | |
| 6557 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6558 | Location ref, |
| 6559 | CpuRegister obj, |
| 6560 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6561 | bool needs_null_check) { |
| 6562 | DCHECK(kEmitCompilerReadBarrier); |
| 6563 | DCHECK(kUseBakerReadBarrier); |
| 6564 | |
| 6565 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6566 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6567 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6568 | } |
| 6569 | |
| 6570 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6571 | Location ref, |
| 6572 | CpuRegister obj, |
| 6573 | uint32_t data_offset, |
| 6574 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6575 | bool needs_null_check) { |
| 6576 | DCHECK(kEmitCompilerReadBarrier); |
| 6577 | DCHECK(kUseBakerReadBarrier); |
| 6578 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6579 | static_assert( |
| 6580 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6581 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6582 | // /* HeapReference<Object> */ ref = |
| 6583 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6584 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_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::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6589 | Location ref, |
| 6590 | CpuRegister obj, |
| 6591 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6592 | bool needs_null_check, |
| 6593 | bool always_update_field, |
| 6594 | CpuRegister* temp1, |
| 6595 | CpuRegister* temp2) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6596 | DCHECK(kEmitCompilerReadBarrier); |
| 6597 | DCHECK(kUseBakerReadBarrier); |
| 6598 | |
| 6599 | // In slow path based read barriers, the read barrier call is |
| 6600 | // inserted after the original load. However, in fast path based |
| 6601 | // Baker's read barriers, we need to perform the load of |
| 6602 | // mirror::Object::monitor_ *before* the original reference load. |
| 6603 | // This load-load ordering is required by the read barrier. |
| 6604 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6605 | // |
| 6606 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6607 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6608 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6609 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6610 | // if (is_gray) { |
| 6611 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6612 | // } |
| 6613 | // |
| 6614 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6615 | // slightly more complex as: |
| 6616 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6617 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6618 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6619 | // 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] | 6620 | // - it performs additional checks that we do not do here for |
| 6621 | // performance reasons. |
| 6622 | |
| 6623 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6624 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6625 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6626 | // 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] | 6627 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6628 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6629 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6630 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6631 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6632 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6633 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6634 | // ref = ReadBarrier::Mark(ref); |
| 6635 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6636 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6637 | if (needs_null_check) { |
| 6638 | MaybeRecordImplicitNullCheck(instruction); |
| 6639 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6640 | |
| 6641 | // Load fence to prevent load-load reordering. |
| 6642 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6643 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6644 | |
| 6645 | // The actual reference load. |
| 6646 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6647 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6648 | |
| 6649 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6650 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6651 | SlowPathCode* slow_path; |
| 6652 | if (always_update_field) { |
| 6653 | DCHECK(temp1 != nullptr); |
| 6654 | DCHECK(temp2 != nullptr); |
| 6655 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
| 6656 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp1, *temp2); |
| 6657 | } else { |
| 6658 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6659 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 6660 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6661 | AddSlowPath(slow_path); |
| 6662 | |
| 6663 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6664 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6665 | |
| 6666 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6667 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6668 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6669 | __ Bind(slow_path->GetExitLabel()); |
| 6670 | } |
| 6671 | |
| 6672 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6673 | Location out, |
| 6674 | Location ref, |
| 6675 | Location obj, |
| 6676 | uint32_t offset, |
| 6677 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6678 | DCHECK(kEmitCompilerReadBarrier); |
| 6679 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6680 | // Insert a slow path based read barrier *after* the reference load. |
| 6681 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6682 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6683 | // reference will be carried out by the runtime within the slow |
| 6684 | // path. |
| 6685 | // |
| 6686 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6687 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6688 | // not used by the artReadBarrierSlow entry point. |
| 6689 | // |
| 6690 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6691 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6692 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6693 | AddSlowPath(slow_path); |
| 6694 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6695 | __ jmp(slow_path->GetEntryLabel()); |
| 6696 | __ Bind(slow_path->GetExitLabel()); |
| 6697 | } |
| 6698 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6699 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6700 | Location out, |
| 6701 | Location ref, |
| 6702 | Location obj, |
| 6703 | uint32_t offset, |
| 6704 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6705 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6706 | // Baker's read barriers shall be handled by the fast path |
| 6707 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6708 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6709 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6710 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6711 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6712 | } else if (kPoisonHeapReferences) { |
| 6713 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6714 | } |
| 6715 | } |
| 6716 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6717 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6718 | Location out, |
| 6719 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6720 | DCHECK(kEmitCompilerReadBarrier); |
| 6721 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6722 | // Insert a slow path based read barrier *after* the GC root load. |
| 6723 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6724 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6725 | // not need to do anything special for this here. |
| 6726 | SlowPathCode* slow_path = |
| 6727 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6728 | AddSlowPath(slow_path); |
| 6729 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6730 | __ jmp(slow_path->GetEntryLabel()); |
| 6731 | __ Bind(slow_path->GetExitLabel()); |
| 6732 | } |
| 6733 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6734 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6735 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6736 | LOG(FATAL) << "Unreachable"; |
| 6737 | } |
| 6738 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6739 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6740 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6741 | LOG(FATAL) << "Unreachable"; |
| 6742 | } |
| 6743 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6744 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6745 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6746 | LocationSummary* locations = |
| 6747 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6748 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6749 | locations->AddTemp(Location::RequiresRegister()); |
| 6750 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6751 | } |
| 6752 | |
| 6753 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6754 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6755 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6756 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6757 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6758 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6759 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6760 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6761 | |
| 6762 | // Should we generate smaller inline compare/jumps? |
| 6763 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6764 | // Figure out the correct compare values and jump conditions. |
| 6765 | // Handle the first compare/branch as a special case because it might |
| 6766 | // jump to the default case. |
| 6767 | DCHECK_GT(num_entries, 2u); |
| 6768 | Condition first_condition; |
| 6769 | uint32_t index; |
| 6770 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6771 | if (lower_bound != 0) { |
| 6772 | first_condition = kLess; |
| 6773 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6774 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6775 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6776 | |
| 6777 | index = 1; |
| 6778 | } else { |
| 6779 | // Handle all the compare/jumps below. |
| 6780 | first_condition = kBelow; |
| 6781 | index = 0; |
| 6782 | } |
| 6783 | |
| 6784 | // Handle the rest of the compare/jumps. |
| 6785 | for (; index + 1 < num_entries; index += 2) { |
| 6786 | int32_t compare_to_value = lower_bound + index + 1; |
| 6787 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6788 | // Jump to successors[index] if value < case_value[index]. |
| 6789 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6790 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6791 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6792 | } |
| 6793 | |
| 6794 | if (index != num_entries) { |
| 6795 | // There are an odd number of entries. Handle the last one. |
| 6796 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6797 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6798 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6799 | } |
| 6800 | |
| 6801 | // And the default for any other value. |
| 6802 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6803 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6804 | } |
| 6805 | return; |
| 6806 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6807 | |
| 6808 | // Remove the bias, if needed. |
| 6809 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6810 | if (lower_bound != 0) { |
| 6811 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6812 | value_reg_out = temp_reg.AsRegister(); |
| 6813 | } |
| 6814 | CpuRegister value_reg(value_reg_out); |
| 6815 | |
| 6816 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6817 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6818 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6819 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6820 | // We are in the range of the table. |
| 6821 | // Load the address of the jump table in the constant area. |
| 6822 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6823 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6824 | // Load the (signed) offset from the jump table. |
| 6825 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6826 | |
| 6827 | // Add the offset to the address of the table base. |
| 6828 | __ addq(temp_reg, base_reg); |
| 6829 | |
| 6830 | // And jump. |
| 6831 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6832 | } |
| 6833 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6834 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6835 | if (value == 0) { |
| 6836 | __ xorl(dest, dest); |
| 6837 | } else { |
| 6838 | __ movl(dest, Immediate(value)); |
| 6839 | } |
| 6840 | } |
| 6841 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6842 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6843 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6844 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6845 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6846 | } else if (IsUint<32>(value)) { |
| 6847 | // 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] | 6848 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6849 | } else { |
| 6850 | __ movq(dest, Immediate(value)); |
| 6851 | } |
| 6852 | } |
| 6853 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6854 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6855 | if (value == 0) { |
| 6856 | __ xorps(dest, dest); |
| 6857 | } else { |
| 6858 | __ movss(dest, LiteralInt32Address(value)); |
| 6859 | } |
| 6860 | } |
| 6861 | |
| 6862 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6863 | if (value == 0) { |
| 6864 | __ xorpd(dest, dest); |
| 6865 | } else { |
| 6866 | __ movsd(dest, LiteralInt64Address(value)); |
| 6867 | } |
| 6868 | } |
| 6869 | |
| 6870 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6871 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6872 | } |
| 6873 | |
| 6874 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6875 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6876 | } |
| 6877 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6878 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6879 | if (value == 0) { |
| 6880 | __ testl(dest, dest); |
| 6881 | } else { |
| 6882 | __ cmpl(dest, Immediate(value)); |
| 6883 | } |
| 6884 | } |
| 6885 | |
| 6886 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6887 | if (IsInt<32>(value)) { |
| 6888 | if (value == 0) { |
| 6889 | __ testq(dest, dest); |
| 6890 | } else { |
| 6891 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6892 | } |
| 6893 | } else { |
| 6894 | // Value won't fit in an int. |
| 6895 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6896 | } |
| 6897 | } |
| 6898 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6899 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 6900 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6901 | GenerateIntCompare(lhs_reg, rhs); |
| 6902 | } |
| 6903 | |
| 6904 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6905 | if (rhs.IsConstant()) { |
| 6906 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6907 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6908 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6909 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6910 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6911 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6912 | } |
| 6913 | } |
| 6914 | |
| 6915 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 6916 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 6917 | if (rhs.IsConstant()) { |
| 6918 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 6919 | Compare64BitValue(lhs_reg, value); |
| 6920 | } else if (rhs.IsDoubleStackSlot()) { |
| 6921 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 6922 | } else { |
| 6923 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 6924 | } |
| 6925 | } |
| 6926 | |
| 6927 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 6928 | Location index, |
| 6929 | ScaleFactor scale, |
| 6930 | uint32_t data_offset) { |
| 6931 | return index.IsConstant() ? |
| 6932 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 6933 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 6934 | } |
| 6935 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6936 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6937 | DCHECK(dest.IsDoubleStackSlot()); |
| 6938 | if (IsInt<32>(value)) { |
| 6939 | // Can move directly as an int32 constant. |
| 6940 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6941 | Immediate(static_cast<int32_t>(value))); |
| 6942 | } else { |
| 6943 | Load64BitValue(CpuRegister(TMP), value); |
| 6944 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6945 | } |
| 6946 | } |
| 6947 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6948 | /** |
| 6949 | * Class to handle late fixup of offsets into constant area. |
| 6950 | */ |
| 6951 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6952 | public: |
| 6953 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6954 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6955 | |
| 6956 | protected: |
| 6957 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6958 | |
| 6959 | CodeGeneratorX86_64* codegen_; |
| 6960 | |
| 6961 | private: |
| 6962 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6963 | // Patch the correct offset for the instruction. We use the address of the |
| 6964 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6965 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6966 | int32_t relative_position = constant_offset - pos; |
| 6967 | |
| 6968 | // Patch in the right value. |
| 6969 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6970 | } |
| 6971 | |
| 6972 | // Location in constant area that the fixup refers to. |
| 6973 | size_t offset_into_constant_area_; |
| 6974 | }; |
| 6975 | |
| 6976 | /** |
| 6977 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6978 | * constant area. |
| 6979 | */ |
| 6980 | class JumpTableRIPFixup : public RIPFixup { |
| 6981 | public: |
| 6982 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6983 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6984 | |
| 6985 | void CreateJumpTable() { |
| 6986 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6987 | |
| 6988 | // Ensure that the reference to the jump table has the correct offset. |
| 6989 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6990 | SetOffset(offset_in_constant_table); |
| 6991 | |
| 6992 | // Compute the offset from the start of the function to this jump table. |
| 6993 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6994 | |
| 6995 | // Populate the jump table with the correct values for the jump table. |
| 6996 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6997 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6998 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6999 | // The value that we want is the target offset - the position of the table. |
| 7000 | for (int32_t i = 0; i < num_entries; i++) { |
| 7001 | HBasicBlock* b = successors[i]; |
| 7002 | Label* l = codegen_->GetLabelOf(b); |
| 7003 | DCHECK(l->IsBound()); |
| 7004 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7005 | assembler->AppendInt32(offset_to_block); |
| 7006 | } |
| 7007 | } |
| 7008 | |
| 7009 | private: |
| 7010 | const HPackedSwitch* switch_instr_; |
| 7011 | }; |
| 7012 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7013 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7014 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7015 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7016 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7017 | // 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] | 7018 | assembler->Align(4, 0); |
| 7019 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7020 | |
| 7021 | // Populate any jump tables. |
| 7022 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7023 | jump_table->CreateJumpTable(); |
| 7024 | } |
| 7025 | |
| 7026 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7027 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7028 | } |
| 7029 | |
| 7030 | // And finish up. |
| 7031 | CodeGenerator::Finalize(allocator); |
| 7032 | } |
| 7033 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7034 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 7035 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7036 | return Address::RIP(fixup); |
| 7037 | } |
| 7038 | |
| 7039 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 7040 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7041 | return Address::RIP(fixup); |
| 7042 | } |
| 7043 | |
| 7044 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 7045 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7046 | return Address::RIP(fixup); |
| 7047 | } |
| 7048 | |
| 7049 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 7050 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7051 | return Address::RIP(fixup); |
| 7052 | } |
| 7053 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7054 | // TODO: trg as memory. |
| 7055 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7056 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7057 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7058 | return; |
| 7059 | } |
| 7060 | |
| 7061 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7062 | |
| 7063 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7064 | if (trg.Equals(return_loc)) { |
| 7065 | return; |
| 7066 | } |
| 7067 | |
| 7068 | // Let the parallel move resolver take care of all of this. |
| 7069 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7070 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7071 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7072 | } |
| 7073 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7074 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7075 | // Create a fixup to be used to create and address the jump table. |
| 7076 | JumpTableRIPFixup* table_fixup = |
| 7077 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7078 | |
| 7079 | // We have to populate the jump tables. |
| 7080 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7081 | return Address::RIP(table_fixup); |
| 7082 | } |
| 7083 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7084 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7085 | const Address& addr_high, |
| 7086 | int64_t v, |
| 7087 | HInstruction* instruction) { |
| 7088 | if (IsInt<32>(v)) { |
| 7089 | int32_t v_32 = v; |
| 7090 | __ movq(addr_low, Immediate(v_32)); |
| 7091 | MaybeRecordImplicitNullCheck(instruction); |
| 7092 | } else { |
| 7093 | // Didn't fit in a register. Do it in pieces. |
| 7094 | int32_t low_v = Low32Bits(v); |
| 7095 | int32_t high_v = High32Bits(v); |
| 7096 | __ movl(addr_low, Immediate(low_v)); |
| 7097 | MaybeRecordImplicitNullCheck(instruction); |
| 7098 | __ movl(addr_high, Immediate(high_v)); |
| 7099 | } |
| 7100 | } |
| 7101 | |
Nicolas Geoffray | ac3ebc3 | 2016-10-05 13:13:50 +0100 | [diff] [blame] | 7102 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7103 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| 7104 | const auto& it = jit_string_roots_.find(StringReference(&info.dex_file, info.index)); |
| 7105 | DCHECK(it != jit_string_roots_.end()); |
| 7106 | size_t index_in_table = it->second; |
| 7107 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7108 | uintptr_t address = |
| 7109 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7110 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7111 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7112 | dchecked_integral_cast<uint32_t>(address); |
| 7113 | } |
| 7114 | } |
| 7115 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7116 | #undef __ |
| 7117 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7118 | } // namespace x86_64 |
| 7119 | } // namespace art |