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)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 1269 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1270 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1271 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1272 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1273 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1274 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1275 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1276 | assembler_(codegen->GetAssembler()), |
| 1277 | codegen_(codegen) {} |
| 1278 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1279 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1280 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1281 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1282 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1283 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1284 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1285 | } |
| 1286 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1287 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1288 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1289 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1290 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1291 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1292 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1293 | } |
| 1294 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1295 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1296 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1297 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1298 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1299 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1300 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1301 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1302 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1303 | __ testq(CpuRegister(RAX), Address( |
| 1304 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1305 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1306 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1307 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1308 | if (HasEmptyFrame()) { |
| 1309 | return; |
| 1310 | } |
| 1311 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1312 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1313 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1314 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1315 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1316 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1317 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1318 | } |
| 1319 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1320 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1321 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1322 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1323 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1324 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1325 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1326 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1327 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1328 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1329 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1330 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1331 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1332 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1333 | } |
| 1334 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1335 | // Save the current method if we need it. Note that we do not |
| 1336 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1337 | // in the SSA graph. |
| 1338 | if (RequiresCurrentMethod()) { |
| 1339 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1340 | CpuRegister(kMethodRegisterArgument)); |
| 1341 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1345 | __ cfi().RememberState(); |
| 1346 | if (!HasEmptyFrame()) { |
| 1347 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1348 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1349 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1350 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1351 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1352 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1353 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1358 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1359 | __ cfi().AdjustCFAOffset(-adjust); |
| 1360 | |
| 1361 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1362 | Register reg = kCoreCalleeSaves[i]; |
| 1363 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1364 | __ popq(CpuRegister(reg)); |
| 1365 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1366 | __ cfi().Restore(DWARFReg(reg)); |
| 1367 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1368 | } |
| 1369 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1370 | __ ret(); |
| 1371 | __ cfi().RestoreState(); |
| 1372 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1373 | } |
| 1374 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1375 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1376 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1377 | } |
| 1378 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1379 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1380 | if (source.Equals(destination)) { |
| 1381 | return; |
| 1382 | } |
| 1383 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1384 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1385 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1386 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1387 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1388 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1389 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1390 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1391 | } else if (source.IsConstant()) { |
| 1392 | HConstant* constant = source.GetConstant(); |
| 1393 | if (constant->IsLongConstant()) { |
| 1394 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1395 | } else { |
| 1396 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1397 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1398 | } else { |
| 1399 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1400 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1401 | } |
| 1402 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1403 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1404 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1405 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1406 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1407 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1408 | } else if (source.IsConstant()) { |
| 1409 | HConstant* constant = source.GetConstant(); |
| 1410 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1411 | if (constant->IsFloatConstant()) { |
| 1412 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1413 | } else { |
| 1414 | Load64BitValue(dest, value); |
| 1415 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1416 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1417 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1418 | } else { |
| 1419 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1420 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1421 | } |
| 1422 | } else if (destination.IsStackSlot()) { |
| 1423 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1424 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1425 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1426 | } else if (source.IsFpuRegister()) { |
| 1427 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1428 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1429 | } else if (source.IsConstant()) { |
| 1430 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1431 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1432 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1433 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1434 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1435 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1436 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1437 | } |
| 1438 | } else { |
| 1439 | DCHECK(destination.IsDoubleStackSlot()); |
| 1440 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1441 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1442 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1443 | } else if (source.IsFpuRegister()) { |
| 1444 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1445 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1446 | } else if (source.IsConstant()) { |
| 1447 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1448 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1449 | int64_t value = GetInt64ValueOf(constant); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1450 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1451 | } else { |
| 1452 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1453 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1454 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1455 | } |
| 1456 | } |
| 1457 | } |
| 1458 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1459 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1460 | DCHECK(location.IsRegister()); |
| 1461 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1462 | } |
| 1463 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1464 | void CodeGeneratorX86_64::MoveLocation( |
| 1465 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1466 | Move(dst, src); |
| 1467 | } |
| 1468 | |
| 1469 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1470 | if (location.IsRegister()) { |
| 1471 | locations->AddTemp(location); |
| 1472 | } else { |
| 1473 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1474 | } |
| 1475 | } |
| 1476 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1477 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1478 | DCHECK(!successor->IsExitBlock()); |
| 1479 | |
| 1480 | HBasicBlock* block = got->GetBlock(); |
| 1481 | HInstruction* previous = got->GetPrevious(); |
| 1482 | |
| 1483 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1484 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1485 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1486 | return; |
| 1487 | } |
| 1488 | |
| 1489 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1490 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1491 | } |
| 1492 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1493 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1494 | } |
| 1495 | } |
| 1496 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1497 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1498 | got->SetLocations(nullptr); |
| 1499 | } |
| 1500 | |
| 1501 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1502 | HandleGoto(got, got->GetSuccessor()); |
| 1503 | } |
| 1504 | |
| 1505 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1506 | try_boundary->SetLocations(nullptr); |
| 1507 | } |
| 1508 | |
| 1509 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1510 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1511 | if (!successor->IsExitBlock()) { |
| 1512 | HandleGoto(try_boundary, successor); |
| 1513 | } |
| 1514 | } |
| 1515 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1516 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1517 | exit->SetLocations(nullptr); |
| 1518 | } |
| 1519 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1520 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1521 | } |
| 1522 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1523 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1524 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1525 | LabelType* true_label, |
| 1526 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1527 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1528 | __ j(kUnordered, true_label); |
| 1529 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1530 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1531 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1532 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1533 | } |
| 1534 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1535 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1536 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1537 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1538 | Location left = locations->InAt(0); |
| 1539 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1540 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1541 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1542 | case Primitive::kPrimBoolean: |
| 1543 | case Primitive::kPrimByte: |
| 1544 | case Primitive::kPrimChar: |
| 1545 | case Primitive::kPrimShort: |
| 1546 | case Primitive::kPrimInt: |
| 1547 | case Primitive::kPrimNot: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1548 | codegen_->GenerateIntCompare(left, right); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1549 | break; |
| 1550 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1551 | case Primitive::kPrimLong: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1552 | codegen_->GenerateLongCompare(left, right); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1553 | break; |
| 1554 | } |
| 1555 | case Primitive::kPrimFloat: { |
| 1556 | if (right.IsFpuRegister()) { |
| 1557 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1558 | } else if (right.IsConstant()) { |
| 1559 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1560 | codegen_->LiteralFloatAddress( |
| 1561 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1562 | } else { |
| 1563 | DCHECK(right.IsStackSlot()); |
| 1564 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1565 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1566 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1567 | break; |
| 1568 | } |
| 1569 | case Primitive::kPrimDouble: { |
| 1570 | if (right.IsFpuRegister()) { |
| 1571 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1572 | } else if (right.IsConstant()) { |
| 1573 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1574 | codegen_->LiteralDoubleAddress( |
| 1575 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1576 | } else { |
| 1577 | DCHECK(right.IsDoubleStackSlot()); |
| 1578 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1579 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1580 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1581 | break; |
| 1582 | } |
| 1583 | default: |
| 1584 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | template<class LabelType> |
| 1589 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1590 | LabelType* true_target_in, |
| 1591 | LabelType* false_target_in) { |
| 1592 | // Generated branching requires both targets to be explicit. If either of the |
| 1593 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1594 | LabelType fallthrough_target; |
| 1595 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1596 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1597 | |
| 1598 | // Generate the comparison to set the CC. |
| 1599 | GenerateCompareTest(condition); |
| 1600 | |
| 1601 | // Now generate the correct jump(s). |
| 1602 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1603 | switch (type) { |
| 1604 | case Primitive::kPrimLong: { |
| 1605 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1606 | break; |
| 1607 | } |
| 1608 | case Primitive::kPrimFloat: { |
| 1609 | GenerateFPJumps(condition, true_target, false_target); |
| 1610 | break; |
| 1611 | } |
| 1612 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1613 | GenerateFPJumps(condition, true_target, false_target); |
| 1614 | break; |
| 1615 | } |
| 1616 | default: |
| 1617 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1618 | } |
| 1619 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1620 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1621 | __ jmp(false_target); |
| 1622 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1623 | |
| 1624 | if (fallthrough_target.IsLinked()) { |
| 1625 | __ Bind(&fallthrough_target); |
| 1626 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1627 | } |
| 1628 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1629 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1630 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1631 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1632 | // conditions if they are materialized due to the complex branching. |
| 1633 | return cond->IsCondition() && |
| 1634 | cond->GetNext() == branch && |
| 1635 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1636 | } |
| 1637 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1638 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1639 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1640 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1641 | LabelType* true_target, |
| 1642 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1643 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1644 | |
| 1645 | if (true_target == nullptr && false_target == nullptr) { |
| 1646 | // Nothing to do. The code always falls through. |
| 1647 | return; |
| 1648 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1649 | // Constant condition, statically compared against "true" (integer value 1). |
| 1650 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1651 | if (true_target != nullptr) { |
| 1652 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1653 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1654 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1655 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1656 | if (false_target != nullptr) { |
| 1657 | __ jmp(false_target); |
| 1658 | } |
| 1659 | } |
| 1660 | return; |
| 1661 | } |
| 1662 | |
| 1663 | // The following code generates these patterns: |
| 1664 | // (1) true_target == nullptr && false_target != nullptr |
| 1665 | // - opposite condition true => branch to false_target |
| 1666 | // (2) true_target != nullptr && false_target == nullptr |
| 1667 | // - condition true => branch to true_target |
| 1668 | // (3) true_target != nullptr && false_target != nullptr |
| 1669 | // - condition true => branch to true_target |
| 1670 | // - branch to false_target |
| 1671 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1672 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1673 | if (true_target == nullptr) { |
| 1674 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1675 | } else { |
| 1676 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1677 | } |
| 1678 | } else { |
| 1679 | // Materialized condition, compare against 0. |
| 1680 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1681 | if (lhs.IsRegister()) { |
| 1682 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1683 | } else { |
| 1684 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1685 | } |
| 1686 | if (true_target == nullptr) { |
| 1687 | __ j(kEqual, false_target); |
| 1688 | } else { |
| 1689 | __ j(kNotEqual, true_target); |
| 1690 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1691 | } |
| 1692 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1693 | // Condition has not been materialized, use its inputs as the |
| 1694 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1695 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1696 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1697 | // If this is a long or FP comparison that has been folded into |
| 1698 | // the HCondition, generate the comparison directly. |
| 1699 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1700 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1701 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1702 | return; |
| 1703 | } |
| 1704 | |
| 1705 | Location lhs = condition->GetLocations()->InAt(0); |
| 1706 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1707 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1708 | if (true_target == nullptr) { |
| 1709 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1710 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1711 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1712 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1713 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1714 | |
| 1715 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1716 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1717 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1718 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1719 | } |
| 1720 | } |
| 1721 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1722 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1723 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1724 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1725 | locations->SetInAt(0, Location::Any()); |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1730 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1731 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1732 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1733 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1734 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1735 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1736 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1740 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1741 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1742 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1743 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1744 | locations->SetInAt(0, Location::Any()); |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1749 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1750 | GenerateTestAndBranch<Label>(deoptimize, |
| 1751 | /* condition_input_index */ 0, |
| 1752 | slow_path->GetEntryLabel(), |
| 1753 | /* false_target */ nullptr); |
| 1754 | } |
| 1755 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1756 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1757 | // There are no conditional move instructions for XMMs. |
| 1758 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1759 | return false; |
| 1760 | } |
| 1761 | |
| 1762 | // A FP condition doesn't generate the single CC that we need. |
| 1763 | HInstruction* condition = select->GetCondition(); |
| 1764 | if (condition->IsCondition() && |
| 1765 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1766 | return false; |
| 1767 | } |
| 1768 | |
| 1769 | // We can generate a CMOV for this Select. |
| 1770 | return true; |
| 1771 | } |
| 1772 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1773 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1774 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1775 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1776 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1777 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1778 | } else { |
| 1779 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1780 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1781 | if (select->InputAt(1)->IsConstant()) { |
| 1782 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1783 | } else { |
| 1784 | locations->SetInAt(1, Location::Any()); |
| 1785 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1786 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1787 | locations->SetInAt(1, Location::Any()); |
| 1788 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1789 | } |
| 1790 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1791 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1792 | } |
| 1793 | locations->SetOut(Location::SameAsFirstInput()); |
| 1794 | } |
| 1795 | |
| 1796 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1797 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1798 | if (SelectCanUseCMOV(select)) { |
| 1799 | // If both the condition and the source types are integer, we can generate |
| 1800 | // a CMOV to implement Select. |
| 1801 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1802 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1803 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1804 | |
| 1805 | HInstruction* select_condition = select->GetCondition(); |
| 1806 | Condition cond = kNotEqual; |
| 1807 | |
| 1808 | // Figure out how to test the 'condition'. |
| 1809 | if (select_condition->IsCondition()) { |
| 1810 | HCondition* condition = select_condition->AsCondition(); |
| 1811 | if (!condition->IsEmittedAtUseSite()) { |
| 1812 | // This was a previously materialized condition. |
| 1813 | // Can we use the existing condition code? |
| 1814 | if (AreEflagsSetFrom(condition, select)) { |
| 1815 | // Materialization was the previous instruction. Condition codes are right. |
| 1816 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1817 | } else { |
| 1818 | // No, we have to recreate the condition code. |
| 1819 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1820 | __ testl(cond_reg, cond_reg); |
| 1821 | } |
| 1822 | } else { |
| 1823 | GenerateCompareTest(condition); |
| 1824 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1825 | } |
| 1826 | } else { |
| 1827 | // Must be a boolean condition, which needs to be compared to 0. |
| 1828 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1829 | __ testl(cond_reg, cond_reg); |
| 1830 | } |
| 1831 | |
| 1832 | // If the condition is true, overwrite the output, which already contains false. |
| 1833 | // Generate the correct sized CMOV. |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1834 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1835 | if (value_true_loc.IsRegister()) { |
| 1836 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1837 | } else { |
| 1838 | __ cmov(cond, |
| 1839 | value_false, |
| 1840 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1841 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1842 | } else { |
| 1843 | NearLabel false_target; |
| 1844 | GenerateTestAndBranch<NearLabel>(select, |
| 1845 | /* condition_input_index */ 2, |
| 1846 | /* true_target */ nullptr, |
| 1847 | &false_target); |
| 1848 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1849 | __ Bind(&false_target); |
| 1850 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1853 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1854 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1855 | } |
| 1856 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1857 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1858 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | void CodeGeneratorX86_64::GenerateNop() { |
| 1862 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1865 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1866 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1867 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1868 | // Handle the long/FP comparisons made in instruction simplification. |
| 1869 | switch (cond->InputAt(0)->GetType()) { |
| 1870 | case Primitive::kPrimLong: |
| 1871 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1872 | locations->SetInAt(1, Location::Any()); |
| 1873 | break; |
| 1874 | case Primitive::kPrimFloat: |
| 1875 | case Primitive::kPrimDouble: |
| 1876 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1877 | locations->SetInAt(1, Location::Any()); |
| 1878 | break; |
| 1879 | default: |
| 1880 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1881 | locations->SetInAt(1, Location::Any()); |
| 1882 | break; |
| 1883 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1884 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1885 | locations->SetOut(Location::RequiresRegister()); |
| 1886 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1887 | } |
| 1888 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1889 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1890 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1891 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1892 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1893 | |
| 1894 | LocationSummary* locations = cond->GetLocations(); |
| 1895 | Location lhs = locations->InAt(0); |
| 1896 | Location rhs = locations->InAt(1); |
| 1897 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1898 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1899 | |
| 1900 | switch (cond->InputAt(0)->GetType()) { |
| 1901 | default: |
| 1902 | // Integer case. |
| 1903 | |
| 1904 | // Clear output register: setcc only sets the low byte. |
| 1905 | __ xorl(reg, reg); |
| 1906 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1907 | codegen_->GenerateIntCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1908 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1909 | return; |
| 1910 | case Primitive::kPrimLong: |
| 1911 | // Clear output register: setcc only sets the low byte. |
| 1912 | __ xorl(reg, reg); |
| 1913 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1914 | codegen_->GenerateLongCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1915 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1916 | return; |
| 1917 | case Primitive::kPrimFloat: { |
| 1918 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1919 | if (rhs.IsConstant()) { |
| 1920 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1921 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1922 | } else if (rhs.IsStackSlot()) { |
| 1923 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1924 | } else { |
| 1925 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1926 | } |
| 1927 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1928 | break; |
| 1929 | } |
| 1930 | case Primitive::kPrimDouble: { |
| 1931 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1932 | if (rhs.IsConstant()) { |
| 1933 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1934 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1935 | } else if (rhs.IsDoubleStackSlot()) { |
| 1936 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1937 | } else { |
| 1938 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1939 | } |
| 1940 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1941 | break; |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1946 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1947 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1948 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1949 | __ Bind(&false_label); |
| 1950 | __ xorl(reg, reg); |
| 1951 | __ jmp(&done_label); |
| 1952 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1953 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1954 | __ Bind(&true_label); |
| 1955 | __ movl(reg, Immediate(1)); |
| 1956 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1960 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1964 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1968 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1972 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1976 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1980 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1984 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1988 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1992 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1996 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2000 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2004 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2005 | } |
| 2006 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2007 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2008 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2012 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2016 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2020 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2024 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2028 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2032 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2036 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2037 | } |
| 2038 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2039 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2040 | LocationSummary* locations = |
| 2041 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2042 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2043 | case Primitive::kPrimBoolean: |
| 2044 | case Primitive::kPrimByte: |
| 2045 | case Primitive::kPrimShort: |
| 2046 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2047 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2048 | case Primitive::kPrimLong: { |
| 2049 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2050 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2051 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2052 | break; |
| 2053 | } |
| 2054 | case Primitive::kPrimFloat: |
| 2055 | case Primitive::kPrimDouble: { |
| 2056 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2057 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2058 | locations->SetOut(Location::RequiresRegister()); |
| 2059 | break; |
| 2060 | } |
| 2061 | default: |
| 2062 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2063 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2067 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2068 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2069 | Location left = locations->InAt(0); |
| 2070 | Location right = locations->InAt(1); |
| 2071 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2072 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2073 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2074 | Condition less_cond = kLess; |
| 2075 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2076 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2077 | case Primitive::kPrimBoolean: |
| 2078 | case Primitive::kPrimByte: |
| 2079 | case Primitive::kPrimShort: |
| 2080 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2081 | case Primitive::kPrimInt: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2082 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2083 | break; |
| 2084 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2085 | case Primitive::kPrimLong: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2086 | codegen_->GenerateLongCompare(left, right); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2087 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2088 | } |
| 2089 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2090 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2091 | if (right.IsConstant()) { |
| 2092 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2093 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2094 | } else if (right.IsStackSlot()) { |
| 2095 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2096 | } else { |
| 2097 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2098 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2099 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2100 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2101 | break; |
| 2102 | } |
| 2103 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2104 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2105 | if (right.IsConstant()) { |
| 2106 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2107 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2108 | } else if (right.IsDoubleStackSlot()) { |
| 2109 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2110 | } else { |
| 2111 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2112 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2113 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2114 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2115 | break; |
| 2116 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2117 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2118 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2119 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2120 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2121 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2122 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2123 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2124 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2125 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2126 | __ movl(out, Immediate(1)); |
| 2127 | __ jmp(&done); |
| 2128 | |
| 2129 | __ Bind(&less); |
| 2130 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2131 | |
| 2132 | __ Bind(&done); |
| 2133 | } |
| 2134 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2135 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2136 | LocationSummary* locations = |
| 2137 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2138 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2139 | } |
| 2140 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2141 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2142 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2143 | } |
| 2144 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2145 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2146 | LocationSummary* locations = |
| 2147 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2148 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2149 | } |
| 2150 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2151 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2152 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2153 | } |
| 2154 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2155 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2156 | LocationSummary* locations = |
| 2157 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2158 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2159 | } |
| 2160 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2161 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2162 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2163 | } |
| 2164 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2165 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2166 | LocationSummary* locations = |
| 2167 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2168 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2169 | } |
| 2170 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2171 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2172 | // Will be generated at use site. |
| 2173 | } |
| 2174 | |
| 2175 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2176 | LocationSummary* locations = |
| 2177 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2178 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2179 | } |
| 2180 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2181 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2182 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2183 | // Will be generated at use site. |
| 2184 | } |
| 2185 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2186 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2187 | memory_barrier->SetLocations(nullptr); |
| 2188 | } |
| 2189 | |
| 2190 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2191 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2192 | } |
| 2193 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2194 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2195 | ret->SetLocations(nullptr); |
| 2196 | } |
| 2197 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2198 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2199 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2203 | LocationSummary* locations = |
| 2204 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2205 | switch (ret->InputAt(0)->GetType()) { |
| 2206 | case Primitive::kPrimBoolean: |
| 2207 | case Primitive::kPrimByte: |
| 2208 | case Primitive::kPrimChar: |
| 2209 | case Primitive::kPrimShort: |
| 2210 | case Primitive::kPrimInt: |
| 2211 | case Primitive::kPrimNot: |
| 2212 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2213 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2214 | break; |
| 2215 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2216 | case Primitive::kPrimFloat: |
| 2217 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2218 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2219 | break; |
| 2220 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2221 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2222 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2223 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2227 | if (kIsDebugBuild) { |
| 2228 | switch (ret->InputAt(0)->GetType()) { |
| 2229 | case Primitive::kPrimBoolean: |
| 2230 | case Primitive::kPrimByte: |
| 2231 | case Primitive::kPrimChar: |
| 2232 | case Primitive::kPrimShort: |
| 2233 | case Primitive::kPrimInt: |
| 2234 | case Primitive::kPrimNot: |
| 2235 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2236 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2237 | break; |
| 2238 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2239 | case Primitive::kPrimFloat: |
| 2240 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2241 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2242 | XMM0); |
| 2243 | break; |
| 2244 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2245 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2246 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2247 | } |
| 2248 | } |
| 2249 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2250 | } |
| 2251 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2252 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2253 | switch (type) { |
| 2254 | case Primitive::kPrimBoolean: |
| 2255 | case Primitive::kPrimByte: |
| 2256 | case Primitive::kPrimChar: |
| 2257 | case Primitive::kPrimShort: |
| 2258 | case Primitive::kPrimInt: |
| 2259 | case Primitive::kPrimNot: |
| 2260 | case Primitive::kPrimLong: |
| 2261 | return Location::RegisterLocation(RAX); |
| 2262 | |
| 2263 | case Primitive::kPrimVoid: |
| 2264 | return Location::NoLocation(); |
| 2265 | |
| 2266 | case Primitive::kPrimDouble: |
| 2267 | case Primitive::kPrimFloat: |
| 2268 | return Location::FpuRegisterLocation(XMM0); |
| 2269 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2270 | |
| 2271 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2275 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2276 | } |
| 2277 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2278 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2279 | switch (type) { |
| 2280 | case Primitive::kPrimBoolean: |
| 2281 | case Primitive::kPrimByte: |
| 2282 | case Primitive::kPrimChar: |
| 2283 | case Primitive::kPrimShort: |
| 2284 | case Primitive::kPrimInt: |
| 2285 | case Primitive::kPrimNot: { |
| 2286 | uint32_t index = gp_index_++; |
| 2287 | stack_index_++; |
| 2288 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2289 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2290 | } else { |
| 2291 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2292 | } |
| 2293 | } |
| 2294 | |
| 2295 | case Primitive::kPrimLong: { |
| 2296 | uint32_t index = gp_index_; |
| 2297 | stack_index_ += 2; |
| 2298 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2299 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2300 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2301 | } else { |
| 2302 | gp_index_ += 2; |
| 2303 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2304 | } |
| 2305 | } |
| 2306 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2307 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2308 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2309 | stack_index_++; |
| 2310 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2311 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2312 | } else { |
| 2313 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2318 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2319 | stack_index_ += 2; |
| 2320 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2321 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2322 | } else { |
| 2323 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2324 | } |
| 2325 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2326 | |
| 2327 | case Primitive::kPrimVoid: |
| 2328 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2329 | break; |
| 2330 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2331 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2332 | } |
| 2333 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2334 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2335 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2336 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2337 | // the method_idx. |
| 2338 | HandleInvoke(invoke); |
| 2339 | } |
| 2340 | |
| 2341 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2342 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2343 | } |
| 2344 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2345 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2346 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2347 | // art::PrepareForRegisterAllocation. |
| 2348 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2349 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2350 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2351 | if (intrinsic.TryDispatch(invoke)) { |
| 2352 | return; |
| 2353 | } |
| 2354 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2355 | HandleInvoke(invoke); |
| 2356 | } |
| 2357 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2358 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2359 | if (invoke->GetLocations()->Intrinsified()) { |
| 2360 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2361 | intrinsic.Dispatch(invoke); |
| 2362 | return true; |
| 2363 | } |
| 2364 | return false; |
| 2365 | } |
| 2366 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2367 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2368 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2369 | // art::PrepareForRegisterAllocation. |
| 2370 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2371 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2372 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2373 | return; |
| 2374 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2375 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2376 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2377 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2378 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2379 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2380 | } |
| 2381 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2382 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2383 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2384 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2385 | } |
| 2386 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2387 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2388 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2389 | if (intrinsic.TryDispatch(invoke)) { |
| 2390 | return; |
| 2391 | } |
| 2392 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2393 | HandleInvoke(invoke); |
| 2394 | } |
| 2395 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2396 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2397 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2398 | return; |
| 2399 | } |
| 2400 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2401 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2402 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2403 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2404 | } |
| 2405 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2406 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2407 | HandleInvoke(invoke); |
| 2408 | // Add the hidden argument. |
| 2409 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2410 | } |
| 2411 | |
| 2412 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2413 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2414 | LocationSummary* locations = invoke->GetLocations(); |
| 2415 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2416 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2417 | Location receiver = locations->InAt(0); |
| 2418 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2419 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2420 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2421 | // won't be modified thereafter, before the `call` instruction. |
| 2422 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2423 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2424 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2425 | if (receiver.IsStackSlot()) { |
| 2426 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2427 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2428 | __ movl(temp, Address(temp, class_offset)); |
| 2429 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2430 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2431 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2432 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2433 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2434 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2435 | // emit a read barrier for the previous class reference load. |
| 2436 | // However this is not required in practice, as this is an |
| 2437 | // intermediate/temporary reference and because the current |
| 2438 | // concurrent copying collector keeps the from-space memory |
| 2439 | // intact/accessible until the end of the marking phase (the |
| 2440 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2441 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2442 | // temp = temp->GetAddressOfIMT() |
| 2443 | __ movq(temp, |
| 2444 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2445 | // temp = temp->GetImtEntryAt(method_offset); |
| 2446 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2447 | invoke->GetImtIndex(), kX86_64PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2448 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2449 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2450 | // call temp->GetEntryPoint(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2451 | __ call(Address( |
| 2452 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2453 | |
| 2454 | DCHECK(!codegen_->IsLeafMethod()); |
| 2455 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2456 | } |
| 2457 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2458 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2459 | LocationSummary* locations = |
| 2460 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2461 | switch (neg->GetResultType()) { |
| 2462 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2463 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2464 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2465 | locations->SetOut(Location::SameAsFirstInput()); |
| 2466 | break; |
| 2467 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2468 | case Primitive::kPrimFloat: |
| 2469 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2470 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2471 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2472 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2473 | break; |
| 2474 | |
| 2475 | default: |
| 2476 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2477 | } |
| 2478 | } |
| 2479 | |
| 2480 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2481 | LocationSummary* locations = neg->GetLocations(); |
| 2482 | Location out = locations->Out(); |
| 2483 | Location in = locations->InAt(0); |
| 2484 | switch (neg->GetResultType()) { |
| 2485 | case Primitive::kPrimInt: |
| 2486 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2487 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2488 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2489 | break; |
| 2490 | |
| 2491 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2492 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2493 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2494 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2495 | break; |
| 2496 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2497 | case Primitive::kPrimFloat: { |
| 2498 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2499 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2500 | // Implement float negation with an exclusive or with value |
| 2501 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2502 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2503 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2504 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2505 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2506 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2507 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2508 | case Primitive::kPrimDouble: { |
| 2509 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2510 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2511 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2512 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2513 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2514 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2515 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2516 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2517 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2518 | |
| 2519 | default: |
| 2520 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2521 | } |
| 2522 | } |
| 2523 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2524 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2525 | LocationSummary* locations = |
| 2526 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2527 | Primitive::Type result_type = conversion->GetResultType(); |
| 2528 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2529 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2530 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2531 | // The Java language does not allow treating boolean as an integral type but |
| 2532 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2533 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2534 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2535 | case Primitive::kPrimByte: |
| 2536 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2537 | case Primitive::kPrimLong: |
| 2538 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2539 | case Primitive::kPrimBoolean: |
| 2540 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2541 | case Primitive::kPrimShort: |
| 2542 | case Primitive::kPrimInt: |
| 2543 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2544 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2545 | locations->SetInAt(0, Location::Any()); |
| 2546 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2547 | break; |
| 2548 | |
| 2549 | default: |
| 2550 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2551 | << " to " << result_type; |
| 2552 | } |
| 2553 | break; |
| 2554 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2555 | case Primitive::kPrimShort: |
| 2556 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2557 | case Primitive::kPrimLong: |
| 2558 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2559 | case Primitive::kPrimBoolean: |
| 2560 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2561 | case Primitive::kPrimByte: |
| 2562 | case Primitive::kPrimInt: |
| 2563 | case Primitive::kPrimChar: |
| 2564 | // Processing a Dex `int-to-short' instruction. |
| 2565 | locations->SetInAt(0, Location::Any()); |
| 2566 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2567 | break; |
| 2568 | |
| 2569 | default: |
| 2570 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2571 | << " to " << result_type; |
| 2572 | } |
| 2573 | break; |
| 2574 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2575 | case Primitive::kPrimInt: |
| 2576 | switch (input_type) { |
| 2577 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2578 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2579 | locations->SetInAt(0, Location::Any()); |
| 2580 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2581 | break; |
| 2582 | |
| 2583 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2584 | // Processing a Dex `float-to-int' instruction. |
| 2585 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2586 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2587 | break; |
| 2588 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2589 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2590 | // Processing a Dex `double-to-int' instruction. |
| 2591 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2592 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2593 | break; |
| 2594 | |
| 2595 | default: |
| 2596 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2597 | << " to " << result_type; |
| 2598 | } |
| 2599 | break; |
| 2600 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2601 | case Primitive::kPrimLong: |
| 2602 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2603 | case Primitive::kPrimBoolean: |
| 2604 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2605 | case Primitive::kPrimByte: |
| 2606 | case Primitive::kPrimShort: |
| 2607 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2608 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2609 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2610 | // TODO: We would benefit from a (to-be-implemented) |
| 2611 | // Location::RegisterOrStackSlot requirement for this input. |
| 2612 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2613 | locations->SetOut(Location::RequiresRegister()); |
| 2614 | break; |
| 2615 | |
| 2616 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2617 | // Processing a Dex `float-to-long' instruction. |
| 2618 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2619 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2620 | break; |
| 2621 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2622 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2623 | // Processing a Dex `double-to-long' instruction. |
| 2624 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2625 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2626 | break; |
| 2627 | |
| 2628 | default: |
| 2629 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2630 | << " to " << result_type; |
| 2631 | } |
| 2632 | break; |
| 2633 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2634 | case Primitive::kPrimChar: |
| 2635 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2636 | case Primitive::kPrimLong: |
| 2637 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2638 | case Primitive::kPrimBoolean: |
| 2639 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2640 | case Primitive::kPrimByte: |
| 2641 | case Primitive::kPrimShort: |
| 2642 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2643 | // Processing a Dex `int-to-char' instruction. |
| 2644 | locations->SetInAt(0, Location::Any()); |
| 2645 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2646 | break; |
| 2647 | |
| 2648 | default: |
| 2649 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2650 | << " to " << result_type; |
| 2651 | } |
| 2652 | break; |
| 2653 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2654 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2655 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2656 | case Primitive::kPrimBoolean: |
| 2657 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2658 | case Primitive::kPrimByte: |
| 2659 | case Primitive::kPrimShort: |
| 2660 | case Primitive::kPrimInt: |
| 2661 | case Primitive::kPrimChar: |
| 2662 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2663 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2664 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2665 | break; |
| 2666 | |
| 2667 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2668 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2669 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2670 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2671 | break; |
| 2672 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2673 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2674 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2675 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2676 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2677 | break; |
| 2678 | |
| 2679 | default: |
| 2680 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2681 | << " to " << result_type; |
| 2682 | }; |
| 2683 | break; |
| 2684 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2685 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2686 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2687 | case Primitive::kPrimBoolean: |
| 2688 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2689 | case Primitive::kPrimByte: |
| 2690 | case Primitive::kPrimShort: |
| 2691 | case Primitive::kPrimInt: |
| 2692 | case Primitive::kPrimChar: |
| 2693 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2694 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2695 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2696 | break; |
| 2697 | |
| 2698 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2699 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2700 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2701 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2702 | break; |
| 2703 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2704 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2705 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2706 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2707 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2708 | break; |
| 2709 | |
| 2710 | default: |
| 2711 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2712 | << " to " << result_type; |
| 2713 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2714 | break; |
| 2715 | |
| 2716 | default: |
| 2717 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2718 | << " to " << result_type; |
| 2719 | } |
| 2720 | } |
| 2721 | |
| 2722 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2723 | LocationSummary* locations = conversion->GetLocations(); |
| 2724 | Location out = locations->Out(); |
| 2725 | Location in = locations->InAt(0); |
| 2726 | Primitive::Type result_type = conversion->GetResultType(); |
| 2727 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2728 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2729 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2730 | case Primitive::kPrimByte: |
| 2731 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2732 | case Primitive::kPrimLong: |
| 2733 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2734 | case Primitive::kPrimBoolean: |
| 2735 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2736 | case Primitive::kPrimShort: |
| 2737 | case Primitive::kPrimInt: |
| 2738 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2739 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2740 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2741 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2742 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2743 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2744 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2745 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2746 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2747 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2748 | } |
| 2749 | break; |
| 2750 | |
| 2751 | default: |
| 2752 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2753 | << " to " << result_type; |
| 2754 | } |
| 2755 | break; |
| 2756 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2757 | case Primitive::kPrimShort: |
| 2758 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2759 | case Primitive::kPrimLong: |
| 2760 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2761 | case Primitive::kPrimBoolean: |
| 2762 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2763 | case Primitive::kPrimByte: |
| 2764 | case Primitive::kPrimInt: |
| 2765 | case Primitive::kPrimChar: |
| 2766 | // Processing a Dex `int-to-short' instruction. |
| 2767 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2768 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2769 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2770 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2771 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2772 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2773 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2774 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2775 | } |
| 2776 | break; |
| 2777 | |
| 2778 | default: |
| 2779 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2780 | << " to " << result_type; |
| 2781 | } |
| 2782 | break; |
| 2783 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2784 | case Primitive::kPrimInt: |
| 2785 | switch (input_type) { |
| 2786 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2787 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2788 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2789 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2790 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2791 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2792 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2793 | } else { |
| 2794 | DCHECK(in.IsConstant()); |
| 2795 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2796 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2797 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2798 | } |
| 2799 | break; |
| 2800 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2801 | case Primitive::kPrimFloat: { |
| 2802 | // Processing a Dex `float-to-int' instruction. |
| 2803 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2804 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2805 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2806 | |
| 2807 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2808 | // if input >= (float)INT_MAX goto done |
| 2809 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2810 | __ j(kAboveEqual, &done); |
| 2811 | // if input == NaN goto nan |
| 2812 | __ j(kUnordered, &nan); |
| 2813 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2814 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2815 | __ jmp(&done); |
| 2816 | __ Bind(&nan); |
| 2817 | // output = 0 |
| 2818 | __ xorl(output, output); |
| 2819 | __ Bind(&done); |
| 2820 | break; |
| 2821 | } |
| 2822 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2823 | case Primitive::kPrimDouble: { |
| 2824 | // Processing a Dex `double-to-int' instruction. |
| 2825 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2826 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2827 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2828 | |
| 2829 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2830 | // if input >= (double)INT_MAX goto done |
| 2831 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2832 | __ j(kAboveEqual, &done); |
| 2833 | // if input == NaN goto nan |
| 2834 | __ j(kUnordered, &nan); |
| 2835 | // output = double-to-int-truncate(input) |
| 2836 | __ cvttsd2si(output, input); |
| 2837 | __ jmp(&done); |
| 2838 | __ Bind(&nan); |
| 2839 | // output = 0 |
| 2840 | __ xorl(output, output); |
| 2841 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2842 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2843 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2844 | |
| 2845 | default: |
| 2846 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2847 | << " to " << result_type; |
| 2848 | } |
| 2849 | break; |
| 2850 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2851 | case Primitive::kPrimLong: |
| 2852 | switch (input_type) { |
| 2853 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2854 | case Primitive::kPrimBoolean: |
| 2855 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2856 | case Primitive::kPrimByte: |
| 2857 | case Primitive::kPrimShort: |
| 2858 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2859 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2860 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2861 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2862 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2863 | break; |
| 2864 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2865 | case Primitive::kPrimFloat: { |
| 2866 | // Processing a Dex `float-to-long' instruction. |
| 2867 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2868 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2869 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2870 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2871 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2872 | // if input >= (float)LONG_MAX goto done |
| 2873 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2874 | __ j(kAboveEqual, &done); |
| 2875 | // if input == NaN goto nan |
| 2876 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2877 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2878 | __ cvttss2si(output, input, true); |
| 2879 | __ jmp(&done); |
| 2880 | __ Bind(&nan); |
| 2881 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2882 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2883 | __ Bind(&done); |
| 2884 | break; |
| 2885 | } |
| 2886 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2887 | case Primitive::kPrimDouble: { |
| 2888 | // Processing a Dex `double-to-long' instruction. |
| 2889 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2890 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2891 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2892 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2893 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2894 | // if input >= (double)LONG_MAX goto done |
| 2895 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2896 | __ j(kAboveEqual, &done); |
| 2897 | // if input == NaN goto nan |
| 2898 | __ j(kUnordered, &nan); |
| 2899 | // output = double-to-long-truncate(input) |
| 2900 | __ cvttsd2si(output, input, true); |
| 2901 | __ jmp(&done); |
| 2902 | __ Bind(&nan); |
| 2903 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2904 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2905 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2906 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2907 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2908 | |
| 2909 | default: |
| 2910 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2911 | << " to " << result_type; |
| 2912 | } |
| 2913 | break; |
| 2914 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2915 | case Primitive::kPrimChar: |
| 2916 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2917 | case Primitive::kPrimLong: |
| 2918 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2919 | case Primitive::kPrimBoolean: |
| 2920 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2921 | case Primitive::kPrimByte: |
| 2922 | case Primitive::kPrimShort: |
| 2923 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2924 | // Processing a Dex `int-to-char' instruction. |
| 2925 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2926 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2927 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2928 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2929 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2930 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2931 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2932 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2933 | } |
| 2934 | break; |
| 2935 | |
| 2936 | default: |
| 2937 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2938 | << " to " << result_type; |
| 2939 | } |
| 2940 | break; |
| 2941 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2942 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2943 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2944 | case Primitive::kPrimBoolean: |
| 2945 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2946 | case Primitive::kPrimByte: |
| 2947 | case Primitive::kPrimShort: |
| 2948 | case Primitive::kPrimInt: |
| 2949 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2950 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2951 | if (in.IsRegister()) { |
| 2952 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2953 | } else if (in.IsConstant()) { |
| 2954 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2955 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2956 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2957 | } else { |
| 2958 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2959 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2960 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2961 | break; |
| 2962 | |
| 2963 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2964 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2965 | if (in.IsRegister()) { |
| 2966 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2967 | } else if (in.IsConstant()) { |
| 2968 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2969 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2970 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2971 | } else { |
| 2972 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2973 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2974 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2975 | break; |
| 2976 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2977 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2978 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2979 | if (in.IsFpuRegister()) { |
| 2980 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2981 | } else if (in.IsConstant()) { |
| 2982 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2983 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2984 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2985 | } else { |
| 2986 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2987 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2988 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2989 | break; |
| 2990 | |
| 2991 | default: |
| 2992 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2993 | << " to " << result_type; |
| 2994 | }; |
| 2995 | break; |
| 2996 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2997 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2998 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2999 | case Primitive::kPrimBoolean: |
| 3000 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3001 | case Primitive::kPrimByte: |
| 3002 | case Primitive::kPrimShort: |
| 3003 | case Primitive::kPrimInt: |
| 3004 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3005 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3006 | if (in.IsRegister()) { |
| 3007 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3008 | } else if (in.IsConstant()) { |
| 3009 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3010 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3011 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3012 | } else { |
| 3013 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3014 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3015 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3016 | break; |
| 3017 | |
| 3018 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3019 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3020 | if (in.IsRegister()) { |
| 3021 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3022 | } else if (in.IsConstant()) { |
| 3023 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3024 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3025 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3026 | } else { |
| 3027 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3028 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3029 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3030 | break; |
| 3031 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3032 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3033 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3034 | if (in.IsFpuRegister()) { |
| 3035 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3036 | } else if (in.IsConstant()) { |
| 3037 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3038 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3039 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3040 | } else { |
| 3041 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3042 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3043 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3044 | break; |
| 3045 | |
| 3046 | default: |
| 3047 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3048 | << " to " << result_type; |
| 3049 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3050 | break; |
| 3051 | |
| 3052 | default: |
| 3053 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3054 | << " to " << result_type; |
| 3055 | } |
| 3056 | } |
| 3057 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3058 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3059 | LocationSummary* locations = |
| 3060 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3061 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3062 | case Primitive::kPrimInt: { |
| 3063 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3064 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3065 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3066 | break; |
| 3067 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3068 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3069 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3070 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3071 | // 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] | 3072 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3073 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3074 | break; |
| 3075 | } |
| 3076 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3077 | case Primitive::kPrimDouble: |
| 3078 | case Primitive::kPrimFloat: { |
| 3079 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3080 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3081 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3082 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3083 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3084 | |
| 3085 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3086 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3087 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3091 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3092 | Location first = locations->InAt(0); |
| 3093 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3094 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3095 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3096 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3097 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3098 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3099 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3100 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3101 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3102 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3103 | } else { |
| 3104 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3105 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3106 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3107 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3108 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3109 | __ addl(out.AsRegister<CpuRegister>(), |
| 3110 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3111 | } else { |
| 3112 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3113 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3114 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3115 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3116 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3117 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3118 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3119 | break; |
| 3120 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3121 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3122 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3123 | if (second.IsRegister()) { |
| 3124 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3125 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3126 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3127 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3128 | } else { |
| 3129 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3130 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3131 | } |
| 3132 | } else { |
| 3133 | DCHECK(second.IsConstant()); |
| 3134 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3135 | int32_t int32_value = Low32Bits(value); |
| 3136 | DCHECK_EQ(int32_value, value); |
| 3137 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3138 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3139 | } else { |
| 3140 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3141 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3142 | } |
| 3143 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3144 | break; |
| 3145 | } |
| 3146 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3147 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3148 | if (second.IsFpuRegister()) { |
| 3149 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3150 | } else if (second.IsConstant()) { |
| 3151 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3152 | codegen_->LiteralFloatAddress( |
| 3153 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3154 | } else { |
| 3155 | DCHECK(second.IsStackSlot()); |
| 3156 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3157 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3158 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3159 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3163 | if (second.IsFpuRegister()) { |
| 3164 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3165 | } else if (second.IsConstant()) { |
| 3166 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3167 | codegen_->LiteralDoubleAddress( |
| 3168 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3169 | } else { |
| 3170 | DCHECK(second.IsDoubleStackSlot()); |
| 3171 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3172 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3173 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3174 | break; |
| 3175 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3176 | |
| 3177 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3178 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3183 | LocationSummary* locations = |
| 3184 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3185 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3186 | case Primitive::kPrimInt: { |
| 3187 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3188 | locations->SetInAt(1, Location::Any()); |
| 3189 | locations->SetOut(Location::SameAsFirstInput()); |
| 3190 | break; |
| 3191 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3192 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3193 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3194 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3195 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3196 | break; |
| 3197 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3198 | case Primitive::kPrimFloat: |
| 3199 | case Primitive::kPrimDouble: { |
| 3200 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3201 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3202 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3203 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3204 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3205 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3206 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3207 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3208 | } |
| 3209 | |
| 3210 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3211 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3212 | Location first = locations->InAt(0); |
| 3213 | Location second = locations->InAt(1); |
| 3214 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3215 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3216 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3217 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3218 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3219 | } else if (second.IsConstant()) { |
| 3220 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3221 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3222 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3223 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3224 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3225 | break; |
| 3226 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3227 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3228 | if (second.IsConstant()) { |
| 3229 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3230 | DCHECK(IsInt<32>(value)); |
| 3231 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3232 | } else { |
| 3233 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3234 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3235 | break; |
| 3236 | } |
| 3237 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3238 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3239 | if (second.IsFpuRegister()) { |
| 3240 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3241 | } else if (second.IsConstant()) { |
| 3242 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3243 | codegen_->LiteralFloatAddress( |
| 3244 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3245 | } else { |
| 3246 | DCHECK(second.IsStackSlot()); |
| 3247 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3248 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3249 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3250 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3254 | if (second.IsFpuRegister()) { |
| 3255 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3256 | } else if (second.IsConstant()) { |
| 3257 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3258 | codegen_->LiteralDoubleAddress( |
| 3259 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3260 | } else { |
| 3261 | DCHECK(second.IsDoubleStackSlot()); |
| 3262 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3263 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3264 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3265 | break; |
| 3266 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3267 | |
| 3268 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3269 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3270 | } |
| 3271 | } |
| 3272 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3273 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3274 | LocationSummary* locations = |
| 3275 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3276 | switch (mul->GetResultType()) { |
| 3277 | case Primitive::kPrimInt: { |
| 3278 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3279 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3280 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3281 | // Can use 3 operand multiply. |
| 3282 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3283 | } else { |
| 3284 | locations->SetOut(Location::SameAsFirstInput()); |
| 3285 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3286 | break; |
| 3287 | } |
| 3288 | case Primitive::kPrimLong: { |
| 3289 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3290 | locations->SetInAt(1, Location::Any()); |
| 3291 | if (mul->InputAt(1)->IsLongConstant() && |
| 3292 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3293 | // Can use 3 operand multiply. |
| 3294 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3295 | } else { |
| 3296 | locations->SetOut(Location::SameAsFirstInput()); |
| 3297 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3298 | break; |
| 3299 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3300 | case Primitive::kPrimFloat: |
| 3301 | case Primitive::kPrimDouble: { |
| 3302 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3303 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3304 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3305 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3306 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3307 | |
| 3308 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3309 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3310 | } |
| 3311 | } |
| 3312 | |
| 3313 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3314 | LocationSummary* locations = mul->GetLocations(); |
| 3315 | Location first = locations->InAt(0); |
| 3316 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3317 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3318 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3319 | case Primitive::kPrimInt: |
| 3320 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3321 | // problems where the output may not be the same as the first operand. |
| 3322 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3323 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3324 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3325 | } else if (second.IsRegister()) { |
| 3326 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3327 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3328 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3329 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3330 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3331 | __ imull(first.AsRegister<CpuRegister>(), |
| 3332 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3333 | } |
| 3334 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3335 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3336 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3337 | // problems where the output may not be the same as the first operand. |
| 3338 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3339 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3340 | if (IsInt<32>(value)) { |
| 3341 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3342 | Immediate(static_cast<int32_t>(value))); |
| 3343 | } else { |
| 3344 | // Have to use the constant area. |
| 3345 | DCHECK(first.Equals(out)); |
| 3346 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3347 | } |
| 3348 | } else if (second.IsRegister()) { |
| 3349 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3350 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3351 | } else { |
| 3352 | DCHECK(second.IsDoubleStackSlot()); |
| 3353 | DCHECK(first.Equals(out)); |
| 3354 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3355 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3356 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3357 | break; |
| 3358 | } |
| 3359 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3360 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3361 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3362 | if (second.IsFpuRegister()) { |
| 3363 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3364 | } else if (second.IsConstant()) { |
| 3365 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3366 | codegen_->LiteralFloatAddress( |
| 3367 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3368 | } else { |
| 3369 | DCHECK(second.IsStackSlot()); |
| 3370 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3371 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3372 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3373 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3377 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3378 | if (second.IsFpuRegister()) { |
| 3379 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3380 | } else if (second.IsConstant()) { |
| 3381 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3382 | codegen_->LiteralDoubleAddress( |
| 3383 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3384 | } else { |
| 3385 | DCHECK(second.IsDoubleStackSlot()); |
| 3386 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3387 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3388 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3389 | break; |
| 3390 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3391 | |
| 3392 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3393 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3394 | } |
| 3395 | } |
| 3396 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3397 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3398 | uint32_t stack_adjustment, bool is_float) { |
| 3399 | if (source.IsStackSlot()) { |
| 3400 | DCHECK(is_float); |
| 3401 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3402 | } else if (source.IsDoubleStackSlot()) { |
| 3403 | DCHECK(!is_float); |
| 3404 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3405 | } else { |
| 3406 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3407 | if (is_float) { |
| 3408 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3409 | codegen_->Move(stack_temp, source); |
| 3410 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3411 | } else { |
| 3412 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3413 | codegen_->Move(stack_temp, source); |
| 3414 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3415 | } |
| 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3420 | Primitive::Type type = rem->GetResultType(); |
| 3421 | bool is_float = type == Primitive::kPrimFloat; |
| 3422 | size_t elem_size = Primitive::ComponentSize(type); |
| 3423 | LocationSummary* locations = rem->GetLocations(); |
| 3424 | Location first = locations->InAt(0); |
| 3425 | Location second = locations->InAt(1); |
| 3426 | Location out = locations->Out(); |
| 3427 | |
| 3428 | // Create stack space for 2 elements. |
| 3429 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3430 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3431 | |
| 3432 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3433 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3434 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3435 | |
| 3436 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3437 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3438 | __ Bind(&retry); |
| 3439 | __ fprem(); |
| 3440 | |
| 3441 | // Move FP status to AX. |
| 3442 | __ fstsw(); |
| 3443 | |
| 3444 | // And see if the argument reduction is complete. This is signaled by the |
| 3445 | // C2 FPU flag bit set to 0. |
| 3446 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3447 | __ j(kNotEqual, &retry); |
| 3448 | |
| 3449 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3450 | // Store FP top of stack to real stack. |
| 3451 | if (is_float) { |
| 3452 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3453 | } else { |
| 3454 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3455 | } |
| 3456 | |
| 3457 | // Pop the 2 items from the FP stack. |
| 3458 | __ fucompp(); |
| 3459 | |
| 3460 | // Load the value from the stack into an XMM register. |
| 3461 | DCHECK(out.IsFpuRegister()) << out; |
| 3462 | if (is_float) { |
| 3463 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3464 | } else { |
| 3465 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3466 | } |
| 3467 | |
| 3468 | // And remove the temporary stack space we allocated. |
| 3469 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3470 | } |
| 3471 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3472 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3473 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3474 | |
| 3475 | LocationSummary* locations = instruction->GetLocations(); |
| 3476 | Location second = locations->InAt(1); |
| 3477 | DCHECK(second.IsConstant()); |
| 3478 | |
| 3479 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3480 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3481 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3482 | |
| 3483 | DCHECK(imm == 1 || imm == -1); |
| 3484 | |
| 3485 | switch (instruction->GetResultType()) { |
| 3486 | case Primitive::kPrimInt: { |
| 3487 | if (instruction->IsRem()) { |
| 3488 | __ xorl(output_register, output_register); |
| 3489 | } else { |
| 3490 | __ movl(output_register, input_register); |
| 3491 | if (imm == -1) { |
| 3492 | __ negl(output_register); |
| 3493 | } |
| 3494 | } |
| 3495 | break; |
| 3496 | } |
| 3497 | |
| 3498 | case Primitive::kPrimLong: { |
| 3499 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3500 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3501 | } else { |
| 3502 | __ movq(output_register, input_register); |
| 3503 | if (imm == -1) { |
| 3504 | __ negq(output_register); |
| 3505 | } |
| 3506 | } |
| 3507 | break; |
| 3508 | } |
| 3509 | |
| 3510 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3511 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3512 | } |
| 3513 | } |
| 3514 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3515 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3516 | LocationSummary* locations = instruction->GetLocations(); |
| 3517 | Location second = locations->InAt(1); |
| 3518 | |
| 3519 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3520 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3521 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3522 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3523 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3524 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3525 | |
| 3526 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3527 | |
| 3528 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3529 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3530 | __ testl(numerator, numerator); |
| 3531 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3532 | int shift = CTZ(imm); |
| 3533 | __ sarl(tmp, Immediate(shift)); |
| 3534 | |
| 3535 | if (imm < 0) { |
| 3536 | __ negl(tmp); |
| 3537 | } |
| 3538 | |
| 3539 | __ movl(output_register, tmp); |
| 3540 | } else { |
| 3541 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3542 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3543 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3544 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3545 | __ addq(rdx, numerator); |
| 3546 | __ testq(numerator, numerator); |
| 3547 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3548 | int shift = CTZ(imm); |
| 3549 | __ sarq(rdx, Immediate(shift)); |
| 3550 | |
| 3551 | if (imm < 0) { |
| 3552 | __ negq(rdx); |
| 3553 | } |
| 3554 | |
| 3555 | __ movq(output_register, rdx); |
| 3556 | } |
| 3557 | } |
| 3558 | |
| 3559 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3560 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3561 | |
| 3562 | LocationSummary* locations = instruction->GetLocations(); |
| 3563 | Location second = locations->InAt(1); |
| 3564 | |
| 3565 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3566 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3567 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3568 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3569 | : locations->Out().AsRegister<CpuRegister>(); |
| 3570 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3571 | |
| 3572 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3573 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3574 | if (instruction->IsDiv()) { |
| 3575 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3576 | } else { |
| 3577 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3578 | } |
| 3579 | |
| 3580 | int64_t magic; |
| 3581 | int shift; |
| 3582 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3583 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3584 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3585 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3586 | |
| 3587 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3588 | |
| 3589 | __ movl(numerator, eax); |
| 3590 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3591 | __ movl(eax, Immediate(magic)); |
| 3592 | __ imull(numerator); |
| 3593 | |
| 3594 | if (imm > 0 && magic < 0) { |
| 3595 | __ addl(edx, numerator); |
| 3596 | } else if (imm < 0 && magic > 0) { |
| 3597 | __ subl(edx, numerator); |
| 3598 | } |
| 3599 | |
| 3600 | if (shift != 0) { |
| 3601 | __ sarl(edx, Immediate(shift)); |
| 3602 | } |
| 3603 | |
| 3604 | __ movl(eax, edx); |
| 3605 | __ shrl(edx, Immediate(31)); |
| 3606 | __ addl(edx, eax); |
| 3607 | |
| 3608 | if (instruction->IsRem()) { |
| 3609 | __ movl(eax, numerator); |
| 3610 | __ imull(edx, Immediate(imm)); |
| 3611 | __ subl(eax, edx); |
| 3612 | __ movl(edx, eax); |
| 3613 | } else { |
| 3614 | __ movl(eax, edx); |
| 3615 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3616 | } else { |
| 3617 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3618 | |
| 3619 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3620 | |
| 3621 | CpuRegister rax = eax; |
| 3622 | CpuRegister rdx = edx; |
| 3623 | |
| 3624 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3625 | |
| 3626 | // Save the numerator. |
| 3627 | __ movq(numerator, rax); |
| 3628 | |
| 3629 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3630 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3631 | |
| 3632 | // RDX:RAX = magic * numerator |
| 3633 | __ imulq(numerator); |
| 3634 | |
| 3635 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3636 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3637 | __ addq(rdx, numerator); |
| 3638 | } else if (imm < 0 && magic > 0) { |
| 3639 | // RDX -= numerator |
| 3640 | __ subq(rdx, numerator); |
| 3641 | } |
| 3642 | |
| 3643 | // Shift if needed. |
| 3644 | if (shift != 0) { |
| 3645 | __ sarq(rdx, Immediate(shift)); |
| 3646 | } |
| 3647 | |
| 3648 | // RDX += 1 if RDX < 0 |
| 3649 | __ movq(rax, rdx); |
| 3650 | __ shrq(rdx, Immediate(63)); |
| 3651 | __ addq(rdx, rax); |
| 3652 | |
| 3653 | if (instruction->IsRem()) { |
| 3654 | __ movq(rax, numerator); |
| 3655 | |
| 3656 | if (IsInt<32>(imm)) { |
| 3657 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3658 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3659 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | __ subq(rax, rdx); |
| 3663 | __ movq(rdx, rax); |
| 3664 | } else { |
| 3665 | __ movq(rax, rdx); |
| 3666 | } |
| 3667 | } |
| 3668 | } |
| 3669 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3670 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3671 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3672 | Primitive::Type type = instruction->GetResultType(); |
| 3673 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3674 | |
| 3675 | bool is_div = instruction->IsDiv(); |
| 3676 | LocationSummary* locations = instruction->GetLocations(); |
| 3677 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3678 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3679 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3680 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3681 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3682 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3683 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3684 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3685 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3686 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3687 | if (imm == 0) { |
| 3688 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3689 | } else if (imm == 1 || imm == -1) { |
| 3690 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3691 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3692 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3693 | } else { |
| 3694 | DCHECK(imm <= -2 || imm >= 2); |
| 3695 | GenerateDivRemWithAnyConstant(instruction); |
| 3696 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3697 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3698 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3699 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3700 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3701 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3702 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3703 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3704 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3705 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3706 | // so it's safe to just use negl instead of more complex comparisons. |
| 3707 | if (type == Primitive::kPrimInt) { |
| 3708 | __ cmpl(second_reg, Immediate(-1)); |
| 3709 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3710 | // edx:eax <- sign-extended of eax |
| 3711 | __ cdq(); |
| 3712 | // eax = quotient, edx = remainder |
| 3713 | __ idivl(second_reg); |
| 3714 | } else { |
| 3715 | __ cmpq(second_reg, Immediate(-1)); |
| 3716 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3717 | // rdx:rax <- sign-extended of rax |
| 3718 | __ cqo(); |
| 3719 | // rax = quotient, rdx = remainder |
| 3720 | __ idivq(second_reg); |
| 3721 | } |
| 3722 | __ Bind(slow_path->GetExitLabel()); |
| 3723 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3724 | } |
| 3725 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3726 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3727 | LocationSummary* locations = |
| 3728 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3729 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3730 | case Primitive::kPrimInt: |
| 3731 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3732 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3733 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3734 | locations->SetOut(Location::SameAsFirstInput()); |
| 3735 | // Intel uses edx:eax as the dividend. |
| 3736 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3737 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3738 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3739 | // output and request another temp. |
| 3740 | if (div->InputAt(1)->IsConstant()) { |
| 3741 | locations->AddTemp(Location::RequiresRegister()); |
| 3742 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3743 | break; |
| 3744 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3745 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3746 | case Primitive::kPrimFloat: |
| 3747 | case Primitive::kPrimDouble: { |
| 3748 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3749 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3750 | locations->SetOut(Location::SameAsFirstInput()); |
| 3751 | break; |
| 3752 | } |
| 3753 | |
| 3754 | default: |
| 3755 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3756 | } |
| 3757 | } |
| 3758 | |
| 3759 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3760 | LocationSummary* locations = div->GetLocations(); |
| 3761 | Location first = locations->InAt(0); |
| 3762 | Location second = locations->InAt(1); |
| 3763 | DCHECK(first.Equals(locations->Out())); |
| 3764 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3765 | Primitive::Type type = div->GetResultType(); |
| 3766 | switch (type) { |
| 3767 | case Primitive::kPrimInt: |
| 3768 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3769 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3770 | break; |
| 3771 | } |
| 3772 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3773 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3774 | if (second.IsFpuRegister()) { |
| 3775 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3776 | } else if (second.IsConstant()) { |
| 3777 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3778 | codegen_->LiteralFloatAddress( |
| 3779 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3780 | } else { |
| 3781 | DCHECK(second.IsStackSlot()); |
| 3782 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3783 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3784 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3785 | break; |
| 3786 | } |
| 3787 | |
| 3788 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3789 | if (second.IsFpuRegister()) { |
| 3790 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3791 | } else if (second.IsConstant()) { |
| 3792 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3793 | codegen_->LiteralDoubleAddress( |
| 3794 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3795 | } else { |
| 3796 | DCHECK(second.IsDoubleStackSlot()); |
| 3797 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3798 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3799 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3800 | break; |
| 3801 | } |
| 3802 | |
| 3803 | default: |
| 3804 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3805 | } |
| 3806 | } |
| 3807 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3808 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3809 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3810 | LocationSummary* locations = |
| 3811 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3812 | |
| 3813 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3814 | case Primitive::kPrimInt: |
| 3815 | case Primitive::kPrimLong: { |
| 3816 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3817 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3818 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3819 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3820 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3821 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3822 | // output and request another temp. |
| 3823 | if (rem->InputAt(1)->IsConstant()) { |
| 3824 | locations->AddTemp(Location::RequiresRegister()); |
| 3825 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3826 | break; |
| 3827 | } |
| 3828 | |
| 3829 | case Primitive::kPrimFloat: |
| 3830 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3831 | locations->SetInAt(0, Location::Any()); |
| 3832 | locations->SetInAt(1, Location::Any()); |
| 3833 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3834 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3835 | break; |
| 3836 | } |
| 3837 | |
| 3838 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3839 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3840 | } |
| 3841 | } |
| 3842 | |
| 3843 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3844 | Primitive::Type type = rem->GetResultType(); |
| 3845 | switch (type) { |
| 3846 | case Primitive::kPrimInt: |
| 3847 | case Primitive::kPrimLong: { |
| 3848 | GenerateDivRemIntegral(rem); |
| 3849 | break; |
| 3850 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3851 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3852 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3853 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3854 | break; |
| 3855 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3856 | default: |
| 3857 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3858 | } |
| 3859 | } |
| 3860 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3861 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3862 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3863 | locations->SetInAt(0, Location::Any()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3864 | } |
| 3865 | |
| 3866 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3867 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3868 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3869 | codegen_->AddSlowPath(slow_path); |
| 3870 | |
| 3871 | LocationSummary* locations = instruction->GetLocations(); |
| 3872 | Location value = locations->InAt(0); |
| 3873 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3874 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3875 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3876 | case Primitive::kPrimByte: |
| 3877 | case Primitive::kPrimChar: |
| 3878 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3879 | case Primitive::kPrimInt: { |
| 3880 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3881 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3882 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3883 | } else if (value.IsStackSlot()) { |
| 3884 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3885 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3886 | } else { |
| 3887 | DCHECK(value.IsConstant()) << value; |
| 3888 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3889 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3890 | } |
| 3891 | } |
| 3892 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3893 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3894 | case Primitive::kPrimLong: { |
| 3895 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3896 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3897 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3898 | } else if (value.IsDoubleStackSlot()) { |
| 3899 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3900 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3901 | } else { |
| 3902 | DCHECK(value.IsConstant()) << value; |
| 3903 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3904 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3905 | } |
| 3906 | } |
| 3907 | break; |
| 3908 | } |
| 3909 | default: |
| 3910 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3911 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3912 | } |
| 3913 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3914 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3915 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3916 | |
| 3917 | LocationSummary* locations = |
| 3918 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3919 | |
| 3920 | switch (op->GetResultType()) { |
| 3921 | case Primitive::kPrimInt: |
| 3922 | case Primitive::kPrimLong: { |
| 3923 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3924 | // The shift count needs to be in CL. |
| 3925 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3926 | locations->SetOut(Location::SameAsFirstInput()); |
| 3927 | break; |
| 3928 | } |
| 3929 | default: |
| 3930 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3931 | } |
| 3932 | } |
| 3933 | |
| 3934 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3935 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3936 | |
| 3937 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3938 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3939 | Location second = locations->InAt(1); |
| 3940 | |
| 3941 | switch (op->GetResultType()) { |
| 3942 | case Primitive::kPrimInt: { |
| 3943 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3944 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3945 | if (op->IsShl()) { |
| 3946 | __ shll(first_reg, second_reg); |
| 3947 | } else if (op->IsShr()) { |
| 3948 | __ sarl(first_reg, second_reg); |
| 3949 | } else { |
| 3950 | __ shrl(first_reg, second_reg); |
| 3951 | } |
| 3952 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3953 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3954 | if (op->IsShl()) { |
| 3955 | __ shll(first_reg, imm); |
| 3956 | } else if (op->IsShr()) { |
| 3957 | __ sarl(first_reg, imm); |
| 3958 | } else { |
| 3959 | __ shrl(first_reg, imm); |
| 3960 | } |
| 3961 | } |
| 3962 | break; |
| 3963 | } |
| 3964 | case Primitive::kPrimLong: { |
| 3965 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3966 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3967 | if (op->IsShl()) { |
| 3968 | __ shlq(first_reg, second_reg); |
| 3969 | } else if (op->IsShr()) { |
| 3970 | __ sarq(first_reg, second_reg); |
| 3971 | } else { |
| 3972 | __ shrq(first_reg, second_reg); |
| 3973 | } |
| 3974 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3975 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3976 | if (op->IsShl()) { |
| 3977 | __ shlq(first_reg, imm); |
| 3978 | } else if (op->IsShr()) { |
| 3979 | __ sarq(first_reg, imm); |
| 3980 | } else { |
| 3981 | __ shrq(first_reg, imm); |
| 3982 | } |
| 3983 | } |
| 3984 | break; |
| 3985 | } |
| 3986 | default: |
| 3987 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3988 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3989 | } |
| 3990 | } |
| 3991 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3992 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3993 | LocationSummary* locations = |
| 3994 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3995 | |
| 3996 | switch (ror->GetResultType()) { |
| 3997 | case Primitive::kPrimInt: |
| 3998 | case Primitive::kPrimLong: { |
| 3999 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4000 | // The shift count needs to be in CL (unless it is a constant). |
| 4001 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 4002 | locations->SetOut(Location::SameAsFirstInput()); |
| 4003 | break; |
| 4004 | } |
| 4005 | default: |
| 4006 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4007 | UNREACHABLE(); |
| 4008 | } |
| 4009 | } |
| 4010 | |
| 4011 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4012 | LocationSummary* locations = ror->GetLocations(); |
| 4013 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4014 | Location second = locations->InAt(1); |
| 4015 | |
| 4016 | switch (ror->GetResultType()) { |
| 4017 | case Primitive::kPrimInt: |
| 4018 | if (second.IsRegister()) { |
| 4019 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4020 | __ rorl(first_reg, second_reg); |
| 4021 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4022 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4023 | __ rorl(first_reg, imm); |
| 4024 | } |
| 4025 | break; |
| 4026 | case Primitive::kPrimLong: |
| 4027 | if (second.IsRegister()) { |
| 4028 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4029 | __ rorq(first_reg, second_reg); |
| 4030 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4031 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4032 | __ rorq(first_reg, imm); |
| 4033 | } |
| 4034 | break; |
| 4035 | default: |
| 4036 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4037 | UNREACHABLE(); |
| 4038 | } |
| 4039 | } |
| 4040 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4041 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4042 | HandleShift(shl); |
| 4043 | } |
| 4044 | |
| 4045 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4046 | HandleShift(shl); |
| 4047 | } |
| 4048 | |
| 4049 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4050 | HandleShift(shr); |
| 4051 | } |
| 4052 | |
| 4053 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4054 | HandleShift(shr); |
| 4055 | } |
| 4056 | |
| 4057 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4058 | HandleShift(ushr); |
| 4059 | } |
| 4060 | |
| 4061 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4062 | HandleShift(ushr); |
| 4063 | } |
| 4064 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4065 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4066 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4067 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4068 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4069 | if (instruction->IsStringAlloc()) { |
| 4070 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4071 | } else { |
| 4072 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4073 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4074 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4075 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4076 | } |
| 4077 | |
| 4078 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4079 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4080 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4081 | if (instruction->IsStringAlloc()) { |
| 4082 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4083 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4084 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4085 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 4086 | __ call(Address(temp, code_offset.SizeValue())); |
| 4087 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4088 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4089 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4090 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4091 | DCHECK(!codegen_->IsLeafMethod()); |
| 4092 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4093 | } |
| 4094 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4095 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 4096 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4097 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4098 | InvokeRuntimeCallingConvention calling_convention; |
| 4099 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4100 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4101 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4102 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4103 | } |
| 4104 | |
| 4105 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 4106 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4107 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 4108 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4109 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4110 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4111 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4112 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4113 | |
| 4114 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4115 | } |
| 4116 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4117 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4118 | LocationSummary* locations = |
| 4119 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4120 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4121 | if (location.IsStackSlot()) { |
| 4122 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4123 | } else if (location.IsDoubleStackSlot()) { |
| 4124 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4125 | } |
| 4126 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4127 | } |
| 4128 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4129 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4130 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4131 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4132 | } |
| 4133 | |
| 4134 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4135 | LocationSummary* locations = |
| 4136 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4137 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4138 | } |
| 4139 | |
| 4140 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4141 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4142 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4143 | } |
| 4144 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4145 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4146 | LocationSummary* locations = |
| 4147 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4148 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4149 | locations->SetOut(Location::RequiresRegister()); |
| 4150 | } |
| 4151 | |
| 4152 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4153 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4154 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4155 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4156 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4157 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4158 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4159 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4160 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4161 | instruction->GetIndex(), kX86_64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4162 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4163 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4164 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4165 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4166 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4167 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4168 | } |
| 4169 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4170 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4171 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4172 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4173 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4174 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4175 | } |
| 4176 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4177 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4178 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4179 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4180 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4181 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4182 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4183 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4184 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4185 | break; |
| 4186 | |
| 4187 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4188 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4189 | break; |
| 4190 | |
| 4191 | default: |
| 4192 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4193 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4194 | } |
| 4195 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4196 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4197 | LocationSummary* locations = |
| 4198 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4199 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4200 | locations->SetOut(Location::SameAsFirstInput()); |
| 4201 | } |
| 4202 | |
| 4203 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4204 | LocationSummary* locations = bool_not->GetLocations(); |
| 4205 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4206 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4207 | Location out = locations->Out(); |
| 4208 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4209 | } |
| 4210 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4211 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4212 | LocationSummary* locations = |
| 4213 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4214 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4215 | locations->SetInAt(i, Location::Any()); |
| 4216 | } |
| 4217 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4218 | } |
| 4219 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4220 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4221 | LOG(FATAL) << "Unimplemented"; |
| 4222 | } |
| 4223 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4224 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4225 | /* |
| 4226 | * 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] | 4227 | * 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] | 4228 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4229 | */ |
| 4230 | switch (kind) { |
| 4231 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4232 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4233 | break; |
| 4234 | } |
| 4235 | case MemBarrierKind::kAnyStore: |
| 4236 | case MemBarrierKind::kLoadAny: |
| 4237 | case MemBarrierKind::kStoreStore: { |
| 4238 | // nop |
| 4239 | break; |
| 4240 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4241 | case MemBarrierKind::kNTStoreStore: |
| 4242 | // Non-Temporal Store/Store needs an explicit fence. |
| 4243 | MemoryFence(/* non-temporal */ true); |
| 4244 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4245 | } |
| 4246 | } |
| 4247 | |
| 4248 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4249 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4250 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4251 | bool object_field_get_with_read_barrier = |
| 4252 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4253 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4254 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4255 | object_field_get_with_read_barrier ? |
| 4256 | LocationSummary::kCallOnSlowPath : |
| 4257 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4258 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4259 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4260 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4261 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4262 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4263 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4264 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4265 | // The output overlaps for an object field get when read barriers |
| 4266 | // are enabled: we do not want the move to overwrite the object's |
| 4267 | // location, as we need it to emit the read barrier. |
| 4268 | locations->SetOut( |
| 4269 | Location::RequiresRegister(), |
| 4270 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4271 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4275 | const FieldInfo& field_info) { |
| 4276 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4277 | |
| 4278 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4279 | Location base_loc = locations->InAt(0); |
| 4280 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4281 | Location out = locations->Out(); |
| 4282 | bool is_volatile = field_info.IsVolatile(); |
| 4283 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4284 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4285 | |
| 4286 | switch (field_type) { |
| 4287 | case Primitive::kPrimBoolean: { |
| 4288 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4289 | break; |
| 4290 | } |
| 4291 | |
| 4292 | case Primitive::kPrimByte: { |
| 4293 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4294 | break; |
| 4295 | } |
| 4296 | |
| 4297 | case Primitive::kPrimShort: { |
| 4298 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4299 | break; |
| 4300 | } |
| 4301 | |
| 4302 | case Primitive::kPrimChar: { |
| 4303 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4304 | break; |
| 4305 | } |
| 4306 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4307 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4308 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4309 | break; |
| 4310 | } |
| 4311 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4312 | case Primitive::kPrimNot: { |
| 4313 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4314 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4315 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4316 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4317 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4318 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4319 | if (is_volatile) { |
| 4320 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4321 | } |
| 4322 | } else { |
| 4323 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4324 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4325 | if (is_volatile) { |
| 4326 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4327 | } |
| 4328 | // If read barriers are enabled, emit read barriers other than |
| 4329 | // Baker's using a slow path (and also unpoison the loaded |
| 4330 | // reference, if heap poisoning is enabled). |
| 4331 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4332 | } |
| 4333 | break; |
| 4334 | } |
| 4335 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4336 | case Primitive::kPrimLong: { |
| 4337 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4338 | break; |
| 4339 | } |
| 4340 | |
| 4341 | case Primitive::kPrimFloat: { |
| 4342 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4343 | break; |
| 4344 | } |
| 4345 | |
| 4346 | case Primitive::kPrimDouble: { |
| 4347 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4348 | break; |
| 4349 | } |
| 4350 | |
| 4351 | case Primitive::kPrimVoid: |
| 4352 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4353 | UNREACHABLE(); |
| 4354 | } |
| 4355 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4356 | if (field_type == Primitive::kPrimNot) { |
| 4357 | // Potential implicit null checks, in the case of reference |
| 4358 | // fields, are handled in the previous switch statement. |
| 4359 | } else { |
| 4360 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4361 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4362 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4363 | if (is_volatile) { |
| 4364 | if (field_type == Primitive::kPrimNot) { |
| 4365 | // Memory barriers, in the case of references, are also handled |
| 4366 | // in the previous switch statement. |
| 4367 | } else { |
| 4368 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4369 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4370 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4371 | } |
| 4372 | |
| 4373 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4374 | const FieldInfo& field_info) { |
| 4375 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4376 | |
| 4377 | LocationSummary* locations = |
| 4378 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4379 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4380 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4381 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4382 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4383 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4384 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4385 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4386 | if (is_volatile) { |
| 4387 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4388 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4389 | } else { |
| 4390 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4391 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4392 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4393 | if (is_volatile) { |
| 4394 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4395 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4396 | } else { |
| 4397 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4398 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4399 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4400 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4401 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4402 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4403 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4404 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4405 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4406 | locations->AddTemp(Location::RequiresRegister()); |
| 4407 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4408 | } |
| 4409 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4410 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4411 | const FieldInfo& field_info, |
| 4412 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4413 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4414 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4415 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4416 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4417 | Location value = locations->InAt(1); |
| 4418 | bool is_volatile = field_info.IsVolatile(); |
| 4419 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4420 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4421 | |
| 4422 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4423 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4424 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4425 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4426 | bool maybe_record_implicit_null_check_done = false; |
| 4427 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4428 | switch (field_type) { |
| 4429 | case Primitive::kPrimBoolean: |
| 4430 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4431 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4432 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4433 | __ movb(Address(base, offset), Immediate(v)); |
| 4434 | } else { |
| 4435 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4436 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4437 | break; |
| 4438 | } |
| 4439 | |
| 4440 | case Primitive::kPrimShort: |
| 4441 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4442 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4443 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4444 | __ movw(Address(base, offset), Immediate(v)); |
| 4445 | } else { |
| 4446 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4447 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4448 | break; |
| 4449 | } |
| 4450 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4451 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4452 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4453 | if (value.IsConstant()) { |
| 4454 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4455 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4456 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4457 | // Note: if heap poisoning is enabled, no need to poison |
| 4458 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4459 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4460 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4461 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4462 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4463 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4464 | __ PoisonHeapReference(temp); |
| 4465 | __ movl(Address(base, offset), temp); |
| 4466 | } else { |
| 4467 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4468 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4469 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4470 | break; |
| 4471 | } |
| 4472 | |
| 4473 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4474 | if (value.IsConstant()) { |
| 4475 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4476 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4477 | Address(base, offset + sizeof(int32_t)), |
| 4478 | v, |
| 4479 | instruction); |
| 4480 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4481 | } else { |
| 4482 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4483 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4484 | break; |
| 4485 | } |
| 4486 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4487 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4488 | if (value.IsConstant()) { |
| 4489 | int32_t v = |
| 4490 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4491 | __ movl(Address(base, offset), Immediate(v)); |
| 4492 | } else { |
| 4493 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4494 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4495 | break; |
| 4496 | } |
| 4497 | |
| 4498 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4499 | if (value.IsConstant()) { |
| 4500 | int64_t v = |
| 4501 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4502 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4503 | Address(base, offset + sizeof(int32_t)), |
| 4504 | v, |
| 4505 | instruction); |
| 4506 | maybe_record_implicit_null_check_done = true; |
| 4507 | } else { |
| 4508 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4509 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4510 | break; |
| 4511 | } |
| 4512 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4513 | case Primitive::kPrimVoid: |
| 4514 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4515 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4516 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4517 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4518 | if (!maybe_record_implicit_null_check_done) { |
| 4519 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4520 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4521 | |
| 4522 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4523 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4524 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4525 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4526 | } |
| 4527 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4528 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4529 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4530 | } |
| 4531 | } |
| 4532 | |
| 4533 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4534 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4535 | } |
| 4536 | |
| 4537 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4538 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4539 | } |
| 4540 | |
| 4541 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4542 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4546 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4547 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4548 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4549 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4550 | HandleFieldGet(instruction); |
| 4551 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4552 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4553 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4554 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4555 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4556 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4557 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4558 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4559 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4560 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4561 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4562 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4563 | } |
| 4564 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4565 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4566 | HUnresolvedInstanceFieldGet* instruction) { |
| 4567 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4568 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4569 | instruction, instruction->GetFieldType(), calling_convention); |
| 4570 | } |
| 4571 | |
| 4572 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4573 | HUnresolvedInstanceFieldGet* instruction) { |
| 4574 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4575 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4576 | instruction->GetFieldType(), |
| 4577 | instruction->GetFieldIndex(), |
| 4578 | instruction->GetDexPc(), |
| 4579 | calling_convention); |
| 4580 | } |
| 4581 | |
| 4582 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4583 | HUnresolvedInstanceFieldSet* instruction) { |
| 4584 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4585 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4586 | instruction, instruction->GetFieldType(), calling_convention); |
| 4587 | } |
| 4588 | |
| 4589 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4590 | HUnresolvedInstanceFieldSet* instruction) { |
| 4591 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4592 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4593 | instruction->GetFieldType(), |
| 4594 | instruction->GetFieldIndex(), |
| 4595 | instruction->GetDexPc(), |
| 4596 | calling_convention); |
| 4597 | } |
| 4598 | |
| 4599 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4600 | HUnresolvedStaticFieldGet* instruction) { |
| 4601 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4602 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4603 | instruction, instruction->GetFieldType(), calling_convention); |
| 4604 | } |
| 4605 | |
| 4606 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4607 | HUnresolvedStaticFieldGet* instruction) { |
| 4608 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4609 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4610 | instruction->GetFieldType(), |
| 4611 | instruction->GetFieldIndex(), |
| 4612 | instruction->GetDexPc(), |
| 4613 | calling_convention); |
| 4614 | } |
| 4615 | |
| 4616 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4617 | HUnresolvedStaticFieldSet* instruction) { |
| 4618 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4619 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4620 | instruction, instruction->GetFieldType(), calling_convention); |
| 4621 | } |
| 4622 | |
| 4623 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4624 | HUnresolvedStaticFieldSet* instruction) { |
| 4625 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4626 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4627 | instruction->GetFieldType(), |
| 4628 | instruction->GetFieldIndex(), |
| 4629 | instruction->GetDexPc(), |
| 4630 | calling_convention); |
| 4631 | } |
| 4632 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4633 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4634 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4635 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4636 | ? Location::RequiresRegister() |
| 4637 | : Location::Any(); |
| 4638 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4639 | } |
| 4640 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4641 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4642 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4643 | return; |
| 4644 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4645 | LocationSummary* locations = instruction->GetLocations(); |
| 4646 | Location obj = locations->InAt(0); |
| 4647 | |
| 4648 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4649 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4650 | } |
| 4651 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4652 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4653 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4654 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4655 | |
| 4656 | LocationSummary* locations = instruction->GetLocations(); |
| 4657 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4658 | |
| 4659 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4660 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4661 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4662 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4663 | } else { |
| 4664 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4665 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4666 | __ jmp(slow_path->GetEntryLabel()); |
| 4667 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4668 | } |
| 4669 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4670 | } |
| 4671 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4672 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4673 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4674 | } |
| 4675 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4676 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4677 | bool object_array_get_with_read_barrier = |
| 4678 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4679 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4680 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4681 | object_array_get_with_read_barrier ? |
| 4682 | LocationSummary::kCallOnSlowPath : |
| 4683 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4684 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4685 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4686 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4687 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4688 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4689 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4690 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4691 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4692 | // The output overlaps for an object array get when read barriers |
| 4693 | // are enabled: we do not want the move to overwrite the array's |
| 4694 | // location, as we need it to emit the read barrier. |
| 4695 | locations->SetOut( |
| 4696 | Location::RequiresRegister(), |
| 4697 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4698 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4699 | } |
| 4700 | |
| 4701 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4702 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4703 | Location obj_loc = locations->InAt(0); |
| 4704 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4705 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4706 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4707 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4708 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4709 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4710 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4711 | case Primitive::kPrimBoolean: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4712 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4713 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4714 | break; |
| 4715 | } |
| 4716 | |
| 4717 | case Primitive::kPrimByte: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4718 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4719 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4720 | break; |
| 4721 | } |
| 4722 | |
| 4723 | case Primitive::kPrimShort: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4724 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4725 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4726 | break; |
| 4727 | } |
| 4728 | |
| 4729 | case Primitive::kPrimChar: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4730 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4731 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 4732 | // Branch cases into compressed and uncompressed for each index's type. |
| 4733 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4734 | NearLabel done, not_compressed; |
| 4735 | __ cmpl(Address(obj, count_offset), Immediate(0)); |
| 4736 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4737 | __ j(kGreaterEqual, ¬_compressed); |
| 4738 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 4739 | __ jmp(&done); |
| 4740 | __ Bind(¬_compressed); |
| 4741 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4742 | __ Bind(&done); |
| 4743 | } else { |
| 4744 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4745 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4746 | break; |
| 4747 | } |
| 4748 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4749 | case Primitive::kPrimInt: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4750 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4751 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4752 | break; |
| 4753 | } |
| 4754 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4755 | case Primitive::kPrimNot: { |
| 4756 | static_assert( |
| 4757 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4758 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4759 | // /* HeapReference<Object> */ out = |
| 4760 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4761 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4762 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4763 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4764 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4765 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4766 | } else { |
| 4767 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4768 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 4769 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4770 | // If read barriers are enabled, emit read barriers other than |
| 4771 | // Baker's using a slow path (and also unpoison the loaded |
| 4772 | // reference, if heap poisoning is enabled). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4773 | if (index.IsConstant()) { |
| 4774 | uint32_t offset = |
| 4775 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4776 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4777 | } else { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4778 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4779 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4780 | } |
| 4781 | } |
| 4782 | break; |
| 4783 | } |
| 4784 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4785 | case Primitive::kPrimLong: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4786 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4787 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4788 | break; |
| 4789 | } |
| 4790 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4791 | case Primitive::kPrimFloat: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4792 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4793 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4794 | break; |
| 4795 | } |
| 4796 | |
| 4797 | case Primitive::kPrimDouble: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4798 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4799 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4800 | break; |
| 4801 | } |
| 4802 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4803 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4804 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4805 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4806 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4807 | |
| 4808 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4809 | // Potential implicit null checks, in the case of reference |
| 4810 | // arrays, are handled in the previous switch statement. |
| 4811 | } else { |
| 4812 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4813 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4817 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4818 | |
| 4819 | bool needs_write_barrier = |
| 4820 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4821 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4822 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4823 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4824 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4825 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4826 | LocationSummary::kCallOnSlowPath : |
| 4827 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4828 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4829 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4830 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4831 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4832 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4833 | } else { |
| 4834 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4835 | } |
| 4836 | |
| 4837 | if (needs_write_barrier) { |
| 4838 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4839 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4840 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4841 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4842 | } |
| 4843 | |
| 4844 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4845 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4846 | Location array_loc = locations->InAt(0); |
| 4847 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4848 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4849 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4850 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4851 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4852 | bool needs_write_barrier = |
| 4853 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4854 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4855 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4856 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4857 | |
| 4858 | switch (value_type) { |
| 4859 | case Primitive::kPrimBoolean: |
| 4860 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4861 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4862 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4863 | if (value.IsRegister()) { |
| 4864 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4865 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4866 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4867 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4868 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4869 | break; |
| 4870 | } |
| 4871 | |
| 4872 | case Primitive::kPrimShort: |
| 4873 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4874 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4875 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4876 | if (value.IsRegister()) { |
| 4877 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4878 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4879 | DCHECK(value.IsConstant()) << value; |
| 4880 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4881 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4882 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4883 | break; |
| 4884 | } |
| 4885 | |
| 4886 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4887 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4888 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4889 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4890 | if (!value.IsRegister()) { |
| 4891 | // Just setting null. |
| 4892 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4893 | DCHECK(value.IsConstant()) << value; |
| 4894 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4895 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4896 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4897 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4898 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4899 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4900 | |
| 4901 | DCHECK(needs_write_barrier); |
| 4902 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4903 | // We cannot use a NearLabel for `done`, as its range may be too |
| 4904 | // short when Baker read barriers are enabled. |
| 4905 | Label done; |
| 4906 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4907 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4908 | Location temp_loc = locations->GetTemp(0); |
| 4909 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4910 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4911 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4912 | codegen_->AddSlowPath(slow_path); |
| 4913 | if (instruction->GetValueCanBeNull()) { |
| 4914 | __ testl(register_value, register_value); |
| 4915 | __ j(kNotEqual, ¬_null); |
| 4916 | __ movl(address, Immediate(0)); |
| 4917 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4918 | __ jmp(&done); |
| 4919 | __ Bind(¬_null); |
| 4920 | } |
| 4921 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4922 | // Note that when Baker read barriers are enabled, the type |
| 4923 | // checks are performed without read barriers. This is fine, |
| 4924 | // even in the case where a class object is in the from-space |
| 4925 | // after the flip, as a comparison involving such a type would |
| 4926 | // not produce a false positive; it may of course produce a |
| 4927 | // false negative, in which case we would take the ArraySet |
| 4928 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4929 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4930 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4931 | __ movl(temp, Address(array, class_offset)); |
| 4932 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4933 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4934 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4935 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4936 | __ movl(temp, Address(temp, component_offset)); |
| 4937 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4938 | // nor the object reference in `register_value->klass`, as |
| 4939 | // we are comparing two poisoned references. |
| 4940 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4941 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4942 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4943 | __ j(kEqual, &do_put); |
| 4944 | // If heap poisoning is enabled, the `temp` reference has |
| 4945 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4946 | __ MaybeUnpoisonHeapReference(temp); |
| 4947 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4948 | // If heap poisoning is enabled, no need to unpoison the |
| 4949 | // heap reference loaded below, as it is only used for a |
| 4950 | // comparison with null. |
| 4951 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 4952 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4953 | __ Bind(&do_put); |
| 4954 | } else { |
| 4955 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4956 | } |
| 4957 | } |
| 4958 | |
| 4959 | if (kPoisonHeapReferences) { |
| 4960 | __ movl(temp, register_value); |
| 4961 | __ PoisonHeapReference(temp); |
| 4962 | __ movl(address, temp); |
| 4963 | } else { |
| 4964 | __ movl(address, register_value); |
| 4965 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4966 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4967 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4968 | } |
| 4969 | |
| 4970 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4971 | codegen_->MarkGCCard( |
| 4972 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4973 | __ Bind(&done); |
| 4974 | |
| 4975 | if (slow_path != nullptr) { |
| 4976 | __ Bind(slow_path->GetExitLabel()); |
| 4977 | } |
| 4978 | |
| 4979 | break; |
| 4980 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4981 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4982 | case Primitive::kPrimInt: { |
| 4983 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4984 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4985 | if (value.IsRegister()) { |
| 4986 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4987 | } else { |
| 4988 | DCHECK(value.IsConstant()) << value; |
| 4989 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4990 | __ movl(address, Immediate(v)); |
| 4991 | } |
| 4992 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4993 | break; |
| 4994 | } |
| 4995 | |
| 4996 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4997 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4998 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4999 | if (value.IsRegister()) { |
| 5000 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5001 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5002 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5003 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5004 | Address address_high = |
| 5005 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5006 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5007 | } |
| 5008 | break; |
| 5009 | } |
| 5010 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5011 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5012 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5013 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5014 | if (value.IsFpuRegister()) { |
| 5015 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5016 | } else { |
| 5017 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5018 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5019 | __ movl(address, Immediate(v)); |
| 5020 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5021 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5022 | break; |
| 5023 | } |
| 5024 | |
| 5025 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5026 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5027 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5028 | if (value.IsFpuRegister()) { |
| 5029 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5030 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5031 | } else { |
| 5032 | int64_t v = |
| 5033 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5034 | Address address_high = |
| 5035 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5036 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5037 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5038 | break; |
| 5039 | } |
| 5040 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5041 | case Primitive::kPrimVoid: |
| 5042 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5043 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5044 | } |
| 5045 | } |
| 5046 | |
| 5047 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5048 | LocationSummary* locations = |
| 5049 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5050 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5051 | if (!instruction->IsEmittedAtUseSite()) { |
| 5052 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5053 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5057 | if (instruction->IsEmittedAtUseSite()) { |
| 5058 | return; |
| 5059 | } |
| 5060 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5061 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5062 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5063 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5064 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5065 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5066 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5067 | // Mask out most significant bit in case the array is String's array of char. |
| 5068 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 5069 | __ andl(out, Immediate(INT32_MAX)); |
| 5070 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5071 | } |
| 5072 | |
| 5073 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5074 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5075 | InvokeRuntimeCallingConvention calling_convention; |
| 5076 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5077 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5078 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5079 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5080 | HInstruction* length = instruction->InputAt(1); |
| 5081 | if (!length->IsEmittedAtUseSite()) { |
| 5082 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5083 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5087 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5088 | Location index_loc = locations->InAt(0); |
| 5089 | Location length_loc = locations->InAt(1); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5090 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5091 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5092 | if (length_loc.IsConstant()) { |
| 5093 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5094 | if (index_loc.IsConstant()) { |
| 5095 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5096 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5097 | if (index < 0 || index >= length) { |
| 5098 | codegen_->AddSlowPath(slow_path); |
| 5099 | __ jmp(slow_path->GetEntryLabel()); |
| 5100 | } else { |
| 5101 | // Some optimization after BCE may have generated this, and we should not |
| 5102 | // generate a bounds check if it is a valid range. |
| 5103 | } |
| 5104 | return; |
| 5105 | } |
| 5106 | |
| 5107 | // We have to reverse the jump condition because the length is the constant. |
| 5108 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5109 | __ cmpl(index_reg, Immediate(length)); |
| 5110 | codegen_->AddSlowPath(slow_path); |
| 5111 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5112 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5113 | HInstruction* array_length = instruction->InputAt(1); |
| 5114 | if (array_length->IsEmittedAtUseSite()) { |
| 5115 | // Address the length field in the array. |
| 5116 | DCHECK(array_length->IsArrayLength()); |
| 5117 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5118 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5119 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5120 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5121 | CpuRegister length_reg = CpuRegister(TMP); |
| 5122 | __ movl(length_reg, array_len); |
| 5123 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| 5124 | __ andl(length_reg, Immediate(INT32_MAX)); |
| 5125 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5126 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5127 | // Checking the bound for general case: |
| 5128 | // Array of char or String's array when the compression feature off. |
| 5129 | if (index_loc.IsConstant()) { |
| 5130 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5131 | __ cmpl(array_len, Immediate(value)); |
| 5132 | } else { |
| 5133 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5134 | } |
| 5135 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5136 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5137 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5138 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5139 | } |
| 5140 | codegen_->AddSlowPath(slow_path); |
| 5141 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5142 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5143 | } |
| 5144 | |
| 5145 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5146 | CpuRegister card, |
| 5147 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5148 | CpuRegister value, |
| 5149 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5150 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5151 | if (value_can_be_null) { |
| 5152 | __ testl(value, value); |
| 5153 | __ j(kEqual, &is_null); |
| 5154 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5155 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5156 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5157 | __ movq(temp, object); |
| 5158 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5159 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5160 | if (value_can_be_null) { |
| 5161 | __ Bind(&is_null); |
| 5162 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5163 | } |
| 5164 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5165 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5166 | LOG(FATAL) << "Unimplemented"; |
| 5167 | } |
| 5168 | |
| 5169 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5170 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5171 | } |
| 5172 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5173 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5174 | LocationSummary* locations = |
| 5175 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5176 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5180 | HBasicBlock* block = instruction->GetBlock(); |
| 5181 | if (block->GetLoopInformation() != nullptr) { |
| 5182 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5183 | // The back edge will generate the suspend check. |
| 5184 | return; |
| 5185 | } |
| 5186 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5187 | // The goto will generate the suspend check. |
| 5188 | return; |
| 5189 | } |
| 5190 | GenerateSuspendCheck(instruction, nullptr); |
| 5191 | } |
| 5192 | |
| 5193 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5194 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5195 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5196 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5197 | if (slow_path == nullptr) { |
| 5198 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5199 | instruction->SetSlowPath(slow_path); |
| 5200 | codegen_->AddSlowPath(slow_path); |
| 5201 | if (successor != nullptr) { |
| 5202 | DCHECK(successor->IsLoopHeader()); |
| 5203 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5204 | } |
| 5205 | } else { |
| 5206 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5207 | } |
| 5208 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5209 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5210 | /* no_rip */ true), |
| 5211 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5212 | if (successor == nullptr) { |
| 5213 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5214 | __ Bind(slow_path->GetReturnLabel()); |
| 5215 | } else { |
| 5216 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5217 | __ jmp(slow_path->GetEntryLabel()); |
| 5218 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5219 | } |
| 5220 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5221 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5222 | return codegen_->GetAssembler(); |
| 5223 | } |
| 5224 | |
| 5225 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5226 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5227 | Location source = move->GetSource(); |
| 5228 | Location destination = move->GetDestination(); |
| 5229 | |
| 5230 | if (source.IsRegister()) { |
| 5231 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5232 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5233 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5234 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5235 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5236 | } else { |
| 5237 | DCHECK(destination.IsDoubleStackSlot()); |
| 5238 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5239 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5240 | } |
| 5241 | } else if (source.IsStackSlot()) { |
| 5242 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5243 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5244 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5245 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5246 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5247 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5248 | } else { |
| 5249 | DCHECK(destination.IsStackSlot()); |
| 5250 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5251 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5252 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5253 | } else if (source.IsDoubleStackSlot()) { |
| 5254 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5255 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5256 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5257 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5258 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5259 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5260 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5261 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5262 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5263 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5264 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5265 | } else if (source.IsConstant()) { |
| 5266 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5267 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5268 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5269 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5270 | if (value == 0) { |
| 5271 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5272 | } else { |
| 5273 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5274 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5275 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5276 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5277 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5278 | } |
| 5279 | } else if (constant->IsLongConstant()) { |
| 5280 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5281 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5282 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5283 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5284 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5285 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5286 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5287 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5288 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5289 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5290 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5291 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5292 | } else { |
| 5293 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5294 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5295 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5296 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5297 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5298 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5299 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5300 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5301 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5302 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5303 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5304 | } else { |
| 5305 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5306 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5307 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5308 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5309 | } else if (source.IsFpuRegister()) { |
| 5310 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5311 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5312 | } else if (destination.IsStackSlot()) { |
| 5313 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5314 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5315 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5316 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5317 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5318 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5319 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5320 | } |
| 5321 | } |
| 5322 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5323 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5324 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5325 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5326 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5327 | } |
| 5328 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5329 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5330 | ScratchRegisterScope ensure_scratch( |
| 5331 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5332 | |
| 5333 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5334 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5335 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5336 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5337 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5338 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5339 | CpuRegister(ensure_scratch.GetRegister())); |
| 5340 | } |
| 5341 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5342 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5343 | __ movq(CpuRegister(TMP), reg1); |
| 5344 | __ movq(reg1, reg2); |
| 5345 | __ movq(reg2, CpuRegister(TMP)); |
| 5346 | } |
| 5347 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5348 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5349 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5350 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5351 | __ movq(reg, CpuRegister(TMP)); |
| 5352 | } |
| 5353 | |
| 5354 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5355 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5356 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5357 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5358 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5359 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5360 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5361 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5362 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5363 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5364 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5365 | } |
| 5366 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5367 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5368 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5369 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5370 | __ movd(reg, CpuRegister(TMP)); |
| 5371 | } |
| 5372 | |
| 5373 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5374 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5375 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5376 | __ movd(reg, CpuRegister(TMP)); |
| 5377 | } |
| 5378 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5379 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5380 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5381 | Location source = move->GetSource(); |
| 5382 | Location destination = move->GetDestination(); |
| 5383 | |
| 5384 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5385 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5386 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5387 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5388 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5389 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5390 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5391 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5392 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5393 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5394 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5395 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5396 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5397 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5398 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5399 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5400 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5401 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5402 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5403 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5404 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5405 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5406 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5407 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5408 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5409 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5410 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5411 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5412 | } |
| 5413 | } |
| 5414 | |
| 5415 | |
| 5416 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5417 | __ pushq(CpuRegister(reg)); |
| 5418 | } |
| 5419 | |
| 5420 | |
| 5421 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5422 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5423 | } |
| 5424 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5425 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5426 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5427 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5428 | Immediate(mirror::Class::kStatusInitialized)); |
| 5429 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5430 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5431 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5432 | } |
| 5433 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5434 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5435 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5436 | switch (desired_class_load_kind) { |
| 5437 | case HLoadClass::LoadKind::kReferrersClass: |
| 5438 | break; |
| 5439 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5440 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5441 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5442 | return HLoadClass::LoadKind::kBootImageLinkTimePcRelative; |
| 5443 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5444 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5445 | break; |
| 5446 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5447 | break; |
| 5448 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5449 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5450 | break; |
| 5451 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5452 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5453 | break; |
| 5454 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5455 | break; |
| 5456 | } |
| 5457 | return desired_class_load_kind; |
| 5458 | } |
| 5459 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5460 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5461 | if (cls->NeedsAccessCheck()) { |
| 5462 | InvokeRuntimeCallingConvention calling_convention; |
| 5463 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5464 | cls, |
| 5465 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5466 | Location::RegisterLocation(RAX), |
| 5467 | /* code_generator_supports_read_barrier */ true); |
| 5468 | return; |
| 5469 | } |
| 5470 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5471 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5472 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5473 | ? LocationSummary::kCallOnSlowPath |
| 5474 | : LocationSummary::kNoCall; |
| 5475 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5476 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5477 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5478 | } |
| 5479 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5480 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5481 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5482 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5483 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5484 | } |
| 5485 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5486 | } |
| 5487 | |
| 5488 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5489 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5490 | if (cls->NeedsAccessCheck()) { |
| 5491 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5492 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5493 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5494 | return; |
| 5495 | } |
| 5496 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5497 | Location out_loc = locations->Out(); |
| 5498 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5499 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5500 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5501 | bool generate_null_check = false; |
| 5502 | switch (cls->GetLoadKind()) { |
| 5503 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5504 | DCHECK(!cls->CanCallRuntime()); |
| 5505 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5506 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5507 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5508 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5509 | cls, |
| 5510 | out_loc, |
| 5511 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5512 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5513 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5514 | break; |
| 5515 | } |
| 5516 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5517 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5518 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5519 | codegen_->RecordTypePatch(cls); |
| 5520 | break; |
| 5521 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5522 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5523 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5524 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5525 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5526 | codegen_->RecordSimplePatch(); |
| 5527 | break; |
| 5528 | } |
| 5529 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5530 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5531 | // /* GcRoot<mirror::Class> */ out = *address |
| 5532 | if (IsUint<32>(cls->GetAddress())) { |
| 5533 | Address address = Address::Absolute(cls->GetAddress(), /* no_rip */ true); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5534 | GenerateGcRootFieldLoad(cls, |
| 5535 | out_loc, |
| 5536 | address, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5537 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5538 | requires_read_barrier); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5539 | } else { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5540 | // TODO: Consider using opcode A1, i.e. movl eax, moff32 (with 64-bit address). |
| 5541 | __ movq(out, Immediate(cls->GetAddress())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5542 | GenerateGcRootFieldLoad(cls, |
| 5543 | out_loc, |
| 5544 | Address(out, 0), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5545 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5546 | requires_read_barrier); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5547 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5548 | generate_null_check = !cls->IsInDexCache(); |
| 5549 | break; |
| 5550 | } |
| 5551 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5552 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 5553 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 5554 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5555 | /* no_rip */ false); |
| 5556 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5557 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5558 | generate_null_check = !cls->IsInDexCache(); |
| 5559 | break; |
| 5560 | } |
| 5561 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5562 | // /* GcRoot<mirror::Class>[] */ out = |
| 5563 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5564 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5565 | __ movq(out, |
| 5566 | Address(current_method, |
| 5567 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
| 5568 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5569 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5570 | cls, |
| 5571 | out_loc, |
| 5572 | Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5573 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5574 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5575 | generate_null_check = !cls->IsInDexCache(); |
| 5576 | break; |
| 5577 | } |
| 5578 | default: |
| 5579 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5580 | UNREACHABLE(); |
| 5581 | } |
| 5582 | |
| 5583 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5584 | DCHECK(cls->CanCallRuntime()); |
| 5585 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5586 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5587 | codegen_->AddSlowPath(slow_path); |
| 5588 | if (generate_null_check) { |
| 5589 | __ testl(out, out); |
| 5590 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5591 | } |
| 5592 | if (cls->MustGenerateClinitCheck()) { |
| 5593 | GenerateClassInitializationCheck(slow_path, out); |
| 5594 | } else { |
| 5595 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5596 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5601 | LocationSummary* locations = |
| 5602 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5603 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5604 | if (check->HasUses()) { |
| 5605 | locations->SetOut(Location::SameAsFirstInput()); |
| 5606 | } |
| 5607 | } |
| 5608 | |
| 5609 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5610 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5611 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5612 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5613 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5614 | GenerateClassInitializationCheck(slow_path, |
| 5615 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5616 | } |
| 5617 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5618 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5619 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5620 | switch (desired_string_load_kind) { |
| 5621 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5622 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5623 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5624 | return HLoadString::LoadKind::kBootImageLinkTimePcRelative; |
| 5625 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5626 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5627 | break; |
| 5628 | case HLoadString::LoadKind::kBootImageAddress: |
| 5629 | break; |
| 5630 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5631 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5632 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5633 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5634 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5635 | break; |
| 5636 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5637 | break; |
| 5638 | } |
| 5639 | return desired_string_load_kind; |
| 5640 | } |
| 5641 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5642 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5643 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5644 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 5645 | ? LocationSummary::kCallOnMainOnly |
| 5646 | : LocationSummary::kCallOnSlowPath) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5647 | : LocationSummary::kNoCall; |
| 5648 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5649 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5650 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 5651 | } else { |
| 5652 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5653 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5654 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5655 | // Rely on the pResolveString and/or marking to save everything. |
| 5656 | // Custom calling convention: RAX serves as both input and output. |
| 5657 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5658 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5659 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5660 | } else { |
| 5661 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5662 | } |
| 5663 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5664 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5668 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5669 | Location out_loc = locations->Out(); |
| 5670 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5671 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5672 | switch (load->GetLoadKind()) { |
| 5673 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5674 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5675 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5676 | return; // No dex cache slow path. |
| 5677 | } |
| 5678 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5679 | DCHECK_NE(load->GetAddress(), 0u); |
| 5680 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5681 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5682 | codegen_->RecordSimplePatch(); |
| 5683 | return; // No dex cache slow path. |
| 5684 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5685 | case HLoadString::LoadKind::kBssEntry: { |
| 5686 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5687 | /* no_rip */ false); |
| 5688 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 5689 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5690 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kEmitCompilerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5691 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5692 | codegen_->AddSlowPath(slow_path); |
| 5693 | __ testl(out, out); |
| 5694 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5695 | __ Bind(slow_path->GetExitLabel()); |
| 5696 | return; |
| 5697 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5698 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5699 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5700 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5701 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5702 | // 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] | 5703 | // Custom calling convention: RAX serves as both input and output. |
| 5704 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex())); |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5705 | codegen_->InvokeRuntime(kQuickResolveString, |
| 5706 | load, |
| 5707 | load->GetDexPc()); |
| 5708 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5709 | } |
| 5710 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5711 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5712 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5713 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5714 | } |
| 5715 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5716 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5717 | LocationSummary* locations = |
| 5718 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5719 | locations->SetOut(Location::RequiresRegister()); |
| 5720 | } |
| 5721 | |
| 5722 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5723 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5724 | } |
| 5725 | |
| 5726 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5727 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5728 | } |
| 5729 | |
| 5730 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5731 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5732 | } |
| 5733 | |
| 5734 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5735 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5736 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5737 | InvokeRuntimeCallingConvention calling_convention; |
| 5738 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5739 | } |
| 5740 | |
| 5741 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5742 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5743 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5744 | } |
| 5745 | |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5746 | static bool CheckCastTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5747 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 5748 | // We need a temporary for holding the iftable length. |
| 5749 | return true; |
| 5750 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5751 | return kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5752 | !kUseBakerReadBarrier && |
| 5753 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5754 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5755 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5756 | } |
| 5757 | |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5758 | static bool InstanceOfTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5759 | return kEmitCompilerReadBarrier && |
| 5760 | !kUseBakerReadBarrier && |
| 5761 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5762 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5763 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5764 | } |
| 5765 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5766 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5767 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5768 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5769 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5770 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5771 | case TypeCheckKind::kExactCheck: |
| 5772 | case TypeCheckKind::kAbstractClassCheck: |
| 5773 | case TypeCheckKind::kClassHierarchyCheck: |
| 5774 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5775 | call_kind = |
| 5776 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5777 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5778 | break; |
| 5779 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5780 | case TypeCheckKind::kUnresolvedCheck: |
| 5781 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5782 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5783 | break; |
| 5784 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5785 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5786 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5787 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5788 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5789 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5790 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5791 | locations->SetInAt(1, Location::Any()); |
| 5792 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5793 | locations->SetOut(Location::RequiresRegister()); |
| 5794 | // When read barriers are enabled, we need a temporary register for |
| 5795 | // some cases. |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5796 | if (InstanceOfTypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5797 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5798 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5799 | } |
| 5800 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5801 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5802 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5803 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5804 | Location obj_loc = locations->InAt(0); |
| 5805 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5806 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5807 | Location out_loc = locations->Out(); |
| 5808 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5809 | Location maybe_temp_loc = InstanceOfTypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5810 | locations->GetTemp(0) : |
| 5811 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5812 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5813 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5814 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5815 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5816 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5817 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5818 | |
| 5819 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5820 | // Avoid null check if we know obj is not null. |
| 5821 | if (instruction->MustDoNullCheck()) { |
| 5822 | __ testl(obj, obj); |
| 5823 | __ j(kEqual, &zero); |
| 5824 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5825 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5826 | // /* HeapReference<Class> */ out = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 5827 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5828 | out_loc, |
| 5829 | obj_loc, |
| 5830 | class_offset, |
| 5831 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5832 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5833 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5834 | case TypeCheckKind::kExactCheck: { |
| 5835 | if (cls.IsRegister()) { |
| 5836 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5837 | } else { |
| 5838 | DCHECK(cls.IsStackSlot()) << cls; |
| 5839 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5840 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5841 | if (zero.IsLinked()) { |
| 5842 | // Classes must be equal for the instanceof to succeed. |
| 5843 | __ j(kNotEqual, &zero); |
| 5844 | __ movl(out, Immediate(1)); |
| 5845 | __ jmp(&done); |
| 5846 | } else { |
| 5847 | __ setcc(kEqual, out); |
| 5848 | // setcc only sets the low byte. |
| 5849 | __ andl(out, Immediate(1)); |
| 5850 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5851 | break; |
| 5852 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5853 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5854 | case TypeCheckKind::kAbstractClassCheck: { |
| 5855 | // If the class is abstract, we eagerly fetch the super class of the |
| 5856 | // object to avoid doing a comparison we know will fail. |
| 5857 | NearLabel loop, success; |
| 5858 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5859 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5860 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5861 | __ testl(out, out); |
| 5862 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5863 | __ j(kEqual, &done); |
| 5864 | if (cls.IsRegister()) { |
| 5865 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5866 | } else { |
| 5867 | DCHECK(cls.IsStackSlot()) << cls; |
| 5868 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5869 | } |
| 5870 | __ j(kNotEqual, &loop); |
| 5871 | __ movl(out, Immediate(1)); |
| 5872 | if (zero.IsLinked()) { |
| 5873 | __ jmp(&done); |
| 5874 | } |
| 5875 | break; |
| 5876 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5877 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5878 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5879 | // Walk over the class hierarchy to find a match. |
| 5880 | NearLabel loop, success; |
| 5881 | __ Bind(&loop); |
| 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(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5889 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5890 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5891 | __ testl(out, out); |
| 5892 | __ j(kNotEqual, &loop); |
| 5893 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5894 | __ jmp(&done); |
| 5895 | __ Bind(&success); |
| 5896 | __ movl(out, Immediate(1)); |
| 5897 | if (zero.IsLinked()) { |
| 5898 | __ jmp(&done); |
| 5899 | } |
| 5900 | break; |
| 5901 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5902 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5903 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5904 | // Do an exact check. |
| 5905 | NearLabel exact_check; |
| 5906 | if (cls.IsRegister()) { |
| 5907 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5908 | } else { |
| 5909 | DCHECK(cls.IsStackSlot()) << cls; |
| 5910 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5911 | } |
| 5912 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5913 | // 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] | 5914 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5915 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5916 | __ testl(out, out); |
| 5917 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5918 | __ j(kEqual, &done); |
| 5919 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5920 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5921 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5922 | __ movl(out, Immediate(1)); |
| 5923 | __ jmp(&done); |
| 5924 | break; |
| 5925 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5926 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5927 | case TypeCheckKind::kArrayCheck: { |
| 5928 | if (cls.IsRegister()) { |
| 5929 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5930 | } else { |
| 5931 | DCHECK(cls.IsStackSlot()) << cls; |
| 5932 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5933 | } |
| 5934 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5935 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5936 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5937 | codegen_->AddSlowPath(slow_path); |
| 5938 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5939 | __ movl(out, Immediate(1)); |
| 5940 | if (zero.IsLinked()) { |
| 5941 | __ jmp(&done); |
| 5942 | } |
| 5943 | break; |
| 5944 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5945 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5946 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5947 | case TypeCheckKind::kInterfaceCheck: { |
| 5948 | // 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] | 5949 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5950 | // cases. |
| 5951 | // |
| 5952 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5953 | // entry point without resorting to a type checking slow path |
| 5954 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5955 | // require to assign fixed registers for the inputs of this |
| 5956 | // HInstanceOf instruction (following the runtime calling |
| 5957 | // convention), which might be cluttered by the potential first |
| 5958 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5959 | // |
| 5960 | // TODO: Introduce a new runtime entry point taking the object |
| 5961 | // to test (instead of its class) as argument, and let it deal |
| 5962 | // with the read barrier issues. This will let us refactor this |
| 5963 | // case of the `switch` code as it was previously (with a direct |
| 5964 | // call to the runtime not using a type checking slow path). |
| 5965 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5966 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5967 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5968 | /* is_fatal */ false); |
| 5969 | codegen_->AddSlowPath(slow_path); |
| 5970 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5971 | if (zero.IsLinked()) { |
| 5972 | __ jmp(&done); |
| 5973 | } |
| 5974 | break; |
| 5975 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5976 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5977 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5978 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5979 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5980 | __ xorl(out, out); |
| 5981 | } |
| 5982 | |
| 5983 | if (done.IsLinked()) { |
| 5984 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5985 | } |
| 5986 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5987 | if (slow_path != nullptr) { |
| 5988 | __ Bind(slow_path->GetExitLabel()); |
| 5989 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5990 | } |
| 5991 | |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 5992 | bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5993 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5994 | case TypeCheckKind::kExactCheck: |
| 5995 | case TypeCheckKind::kAbstractClassCheck: |
| 5996 | case TypeCheckKind::kClassHierarchyCheck: |
| 5997 | case TypeCheckKind::kArrayObjectCheck: |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 5998 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5999 | case TypeCheckKind::kInterfaceCheck: |
| 6000 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6001 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6002 | case TypeCheckKind::kUnresolvedCheck: |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6003 | return false; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6004 | } |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6005 | LOG(FATAL) << "Unreachable"; |
| 6006 | UNREACHABLE(); |
| 6007 | } |
| 6008 | |
| 6009 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 6010 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6011 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6012 | bool is_fatal_slow_path = IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch); |
| 6013 | LocationSummary::CallKind call_kind = is_fatal_slow_path |
| 6014 | ? LocationSummary::kNoCall |
| 6015 | : LocationSummary::kCallOnSlowPath; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6016 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6017 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6018 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6019 | // Require a register for the interface check since there is a loop that compares the class to |
| 6020 | // a memory address. |
| 6021 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6022 | } else { |
| 6023 | locations->SetInAt(1, Location::Any()); |
| 6024 | } |
| 6025 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6026 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 6027 | locations->AddTemp(Location::RequiresRegister()); |
| 6028 | // When read barriers are enabled, we need an additional temporary |
| 6029 | // register for some cases. |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6030 | if (CheckCastTypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6031 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6032 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6033 | } |
| 6034 | |
| 6035 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6036 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6037 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6038 | Location obj_loc = locations->InAt(0); |
| 6039 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6040 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6041 | Location temp_loc = locations->GetTemp(0); |
| 6042 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6043 | Location maybe_temp2_loc = CheckCastTypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6044 | locations->GetTemp(1) : |
| 6045 | Location::NoLocation(); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6046 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6047 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6048 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6049 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6050 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6051 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6052 | const int object_array_data_offset = mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6053 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6054 | bool is_type_check_slow_path_fatal = |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6055 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6056 | SlowPathCode* type_check_slow_path = |
| 6057 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6058 | is_type_check_slow_path_fatal); |
| 6059 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6060 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6061 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6062 | case TypeCheckKind::kExactCheck: |
| 6063 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6064 | NearLabel done; |
| 6065 | // Avoid null check if we know obj is not null. |
| 6066 | if (instruction->MustDoNullCheck()) { |
| 6067 | __ testl(obj, obj); |
| 6068 | __ j(kEqual, &done); |
| 6069 | } |
| 6070 | |
| 6071 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6072 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6073 | temp_loc, |
| 6074 | obj_loc, |
| 6075 | class_offset, |
| 6076 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6077 | if (cls.IsRegister()) { |
| 6078 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6079 | } else { |
| 6080 | DCHECK(cls.IsStackSlot()) << cls; |
| 6081 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6082 | } |
| 6083 | // Jump to slow path for throwing the exception or doing a |
| 6084 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6085 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6086 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6087 | break; |
| 6088 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6089 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6090 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6091 | NearLabel done; |
| 6092 | // Avoid null check if we know obj is not null. |
| 6093 | if (instruction->MustDoNullCheck()) { |
| 6094 | __ testl(obj, obj); |
| 6095 | __ j(kEqual, &done); |
| 6096 | } |
| 6097 | |
| 6098 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6099 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6100 | temp_loc, |
| 6101 | obj_loc, |
| 6102 | class_offset, |
| 6103 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6104 | // If the class is abstract, we eagerly fetch the super class of the |
| 6105 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6106 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6107 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6108 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6109 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6110 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6111 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6112 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6113 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6114 | // Otherwise, compare the classes. |
| 6115 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6116 | if (cls.IsRegister()) { |
| 6117 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6118 | } else { |
| 6119 | DCHECK(cls.IsStackSlot()) << cls; |
| 6120 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6121 | } |
| 6122 | __ j(kNotEqual, &loop); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6123 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6124 | break; |
| 6125 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6126 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6127 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6128 | NearLabel done; |
| 6129 | // Avoid null check if we know obj is not null. |
| 6130 | if (instruction->MustDoNullCheck()) { |
| 6131 | __ testl(obj, obj); |
| 6132 | __ j(kEqual, &done); |
| 6133 | } |
| 6134 | |
| 6135 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6136 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6137 | temp_loc, |
| 6138 | obj_loc, |
| 6139 | class_offset, |
| 6140 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6141 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6142 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6143 | __ Bind(&loop); |
| 6144 | if (cls.IsRegister()) { |
| 6145 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6146 | } else { |
| 6147 | DCHECK(cls.IsStackSlot()) << cls; |
| 6148 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6149 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6150 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6151 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6152 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6153 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6154 | |
| 6155 | // If the class reference currently in `temp` is not null, jump |
| 6156 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6157 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6158 | __ j(kNotZero, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6159 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6160 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6161 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6162 | break; |
| 6163 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6164 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6165 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6166 | // We cannot use a NearLabel here, as its range might be too |
| 6167 | // short in some cases when read barriers are enabled. This has |
| 6168 | // been observed for instance when the code emitted for this |
| 6169 | // case uses high x86-64 registers (R8-R15). |
| 6170 | Label done; |
| 6171 | // Avoid null check if we know obj is not null. |
| 6172 | if (instruction->MustDoNullCheck()) { |
| 6173 | __ testl(obj, obj); |
| 6174 | __ j(kEqual, &done); |
| 6175 | } |
| 6176 | |
| 6177 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6178 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6179 | temp_loc, |
| 6180 | obj_loc, |
| 6181 | class_offset, |
| 6182 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6183 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6184 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6185 | if (cls.IsRegister()) { |
| 6186 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6187 | } else { |
| 6188 | DCHECK(cls.IsStackSlot()) << cls; |
| 6189 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6190 | } |
| 6191 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6192 | |
| 6193 | // 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] | 6194 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6195 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6196 | |
| 6197 | // If the component type is not null (i.e. the object is indeed |
| 6198 | // an array), jump to label `check_non_primitive_component_type` |
| 6199 | // to further check that this component type is not a primitive |
| 6200 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6201 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6202 | // Otherwise, jump to the slow path to throw the exception. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6203 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6204 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6205 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6206 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6207 | break; |
| 6208 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6209 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6210 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6211 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6212 | NearLabel done; |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6213 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6214 | // Avoid null check if we know obj is not null. |
| 6215 | if (instruction->MustDoNullCheck()) { |
| 6216 | __ testl(obj, obj); |
| 6217 | __ j(kEqual, &done); |
| 6218 | } |
| 6219 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6220 | |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6221 | // 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] | 6222 | // |
| 6223 | // We cannot directly call the CheckCast runtime entry point |
| 6224 | // without resorting to a type checking slow path here (i.e. by |
| 6225 | // calling InvokeRuntime directly), as it would require to |
| 6226 | // assign fixed registers for the inputs of this HInstanceOf |
| 6227 | // instruction (following the runtime calling convention), which |
| 6228 | // might be cluttered by the potential first read barrier |
| 6229 | // emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6230 | // |
| 6231 | // TODO: Introduce a new runtime entry point taking the object |
| 6232 | // to test (instead of its class) as argument, and let it deal |
| 6233 | // with the read barrier issues. This will let us refactor this |
| 6234 | // case of the `switch` code as it was previously (with a direct |
| 6235 | // call to the runtime not using a type checking slow path). |
| 6236 | // This should also be beneficial for the other cases above. |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6237 | |
| 6238 | // Fast path for the interface check. Since we compare with a memory location in the inner |
| 6239 | // loop we would need to have cls poisoned. However unpoisoning cls would reset the |
| 6240 | // conditional flags and cause the conditional jump to be incorrect. |
| 6241 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| 6242 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6243 | // doing this. |
| 6244 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6245 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6246 | temp_loc, |
| 6247 | obj_loc, |
| 6248 | class_offset, |
| 6249 | /*emit_read_barrier*/ false); |
| 6250 | |
| 6251 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6252 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6253 | temp_loc, |
| 6254 | temp_loc, |
| 6255 | iftable_offset, |
| 6256 | /*emit_read_barrier*/ false); |
| 6257 | NearLabel is_null; |
| 6258 | // Null iftable means it is empty. |
| 6259 | __ testl(temp_loc.AsRegister<CpuRegister>(), temp_loc.AsRegister<CpuRegister>()); |
| 6260 | __ j(kZero, &is_null); |
| 6261 | |
| 6262 | // Loop through the iftable and check if any class matches. |
| 6263 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), |
| 6264 | Address(temp_loc.AsRegister<CpuRegister>(), array_length_offset)); |
| 6265 | |
| 6266 | NearLabel start_loop; |
| 6267 | __ Bind(&start_loop); |
| 6268 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 6269 | Address(temp_loc.AsRegister<CpuRegister>(), object_array_data_offset)); |
| 6270 | __ j(kEqual, &done); // Return if same class. |
| 6271 | // Go to next interface. |
| 6272 | __ addq(temp_loc.AsRegister<CpuRegister>(), Immediate(2 * kHeapReferenceSize)); |
| 6273 | __ subq(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| 6274 | __ j(kNotZero, &start_loop); |
| 6275 | __ Bind(&is_null); |
| 6276 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6277 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6278 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6279 | break; |
| 6280 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6281 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6282 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6283 | } |
| 6284 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6285 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6286 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6287 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6288 | InvokeRuntimeCallingConvention calling_convention; |
| 6289 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6290 | } |
| 6291 | |
| 6292 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6293 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6294 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6295 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6296 | if (instruction->IsEnter()) { |
| 6297 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6298 | } else { |
| 6299 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6300 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6301 | } |
| 6302 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6303 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6304 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6305 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6306 | |
| 6307 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6308 | LocationSummary* locations = |
| 6309 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6310 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6311 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6312 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6313 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6314 | locations->SetOut(Location::SameAsFirstInput()); |
| 6315 | } |
| 6316 | |
| 6317 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6318 | HandleBitwiseOperation(instruction); |
| 6319 | } |
| 6320 | |
| 6321 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6322 | HandleBitwiseOperation(instruction); |
| 6323 | } |
| 6324 | |
| 6325 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6326 | HandleBitwiseOperation(instruction); |
| 6327 | } |
| 6328 | |
| 6329 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6330 | LocationSummary* locations = instruction->GetLocations(); |
| 6331 | Location first = locations->InAt(0); |
| 6332 | Location second = locations->InAt(1); |
| 6333 | DCHECK(first.Equals(locations->Out())); |
| 6334 | |
| 6335 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6336 | if (second.IsRegister()) { |
| 6337 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6338 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6339 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6340 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6341 | } else { |
| 6342 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6343 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6344 | } |
| 6345 | } else if (second.IsConstant()) { |
| 6346 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6347 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6348 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6349 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6350 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6351 | } else { |
| 6352 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6353 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6354 | } |
| 6355 | } else { |
| 6356 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6357 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6358 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6359 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6360 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6361 | } else { |
| 6362 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6363 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6364 | } |
| 6365 | } |
| 6366 | } else { |
| 6367 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6368 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6369 | bool second_is_constant = false; |
| 6370 | int64_t value = 0; |
| 6371 | if (second.IsConstant()) { |
| 6372 | second_is_constant = true; |
| 6373 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6374 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6375 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6376 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6377 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6378 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6379 | if (is_int32_value) { |
| 6380 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6381 | } else { |
| 6382 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6383 | } |
| 6384 | } else if (second.IsDoubleStackSlot()) { |
| 6385 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6386 | } else { |
| 6387 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6388 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6389 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6390 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6391 | if (is_int32_value) { |
| 6392 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6393 | } else { |
| 6394 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6395 | } |
| 6396 | } else if (second.IsDoubleStackSlot()) { |
| 6397 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6398 | } else { |
| 6399 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6400 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6401 | } else { |
| 6402 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6403 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6404 | if (is_int32_value) { |
| 6405 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6406 | } else { |
| 6407 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6408 | } |
| 6409 | } else if (second.IsDoubleStackSlot()) { |
| 6410 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6411 | } else { |
| 6412 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6413 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6414 | } |
| 6415 | } |
| 6416 | } |
| 6417 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6418 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6419 | Location out, |
| 6420 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6421 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6422 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6423 | if (kEmitCompilerReadBarrier) { |
| 6424 | if (kUseBakerReadBarrier) { |
| 6425 | // Load with fast path based Baker's read barrier. |
| 6426 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6427 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6428 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6429 | } else { |
| 6430 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6431 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6432 | // in the following move operation, as we will need it for the |
| 6433 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6434 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6435 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6436 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6437 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6438 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6439 | } |
| 6440 | } else { |
| 6441 | // Plain load with no read barrier. |
| 6442 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6443 | __ movl(out_reg, Address(out_reg, offset)); |
| 6444 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6445 | } |
| 6446 | } |
| 6447 | |
| 6448 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6449 | Location out, |
| 6450 | Location obj, |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6451 | uint32_t offset, |
| 6452 | bool emit_read_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6453 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6454 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6455 | if (emit_read_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6456 | if (kUseBakerReadBarrier) { |
| 6457 | // Load with fast path based Baker's read barrier. |
| 6458 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6459 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6460 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6461 | } else { |
| 6462 | // Load with slow path based read barrier. |
| 6463 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6464 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6465 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6466 | } |
| 6467 | } else { |
| 6468 | // Plain load with no read barrier. |
| 6469 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6470 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6471 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6472 | } |
| 6473 | } |
| 6474 | |
| 6475 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6476 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6477 | const Address& address, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6478 | Label* fixup_label, |
| 6479 | bool requires_read_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6480 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6481 | if (requires_read_barrier) { |
| 6482 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6483 | if (kUseBakerReadBarrier) { |
| 6484 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6485 | // Baker's read barrier are used: |
| 6486 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6487 | // root = *address; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6488 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6489 | // root = ReadBarrier::Mark(root) |
| 6490 | // } |
| 6491 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6492 | // /* GcRoot<mirror::Object> */ root = *address |
| 6493 | __ movl(root_reg, address); |
| 6494 | if (fixup_label != nullptr) { |
| 6495 | __ Bind(fixup_label); |
| 6496 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6497 | static_assert( |
| 6498 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6499 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6500 | "have different sizes."); |
| 6501 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6502 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6503 | "have different sizes."); |
| 6504 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6505 | // Slow path marking the GC root `root`. |
| 6506 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6507 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6508 | codegen_->AddSlowPath(slow_path); |
| 6509 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6510 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6511 | /* no_rip */ true), |
| 6512 | Immediate(0)); |
| 6513 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6514 | __ Bind(slow_path->GetExitLabel()); |
| 6515 | } else { |
| 6516 | // GC root loaded through a slow path for read barriers other |
| 6517 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6518 | // /* GcRoot<mirror::Object>* */ root = address |
| 6519 | __ leaq(root_reg, address); |
| 6520 | if (fixup_label != nullptr) { |
| 6521 | __ Bind(fixup_label); |
| 6522 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6523 | // /* mirror::Object* */ root = root->Read() |
| 6524 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6525 | } |
| 6526 | } else { |
| 6527 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6528 | // /* GcRoot<mirror::Object> */ root = *address |
| 6529 | __ movl(root_reg, address); |
| 6530 | if (fixup_label != nullptr) { |
| 6531 | __ Bind(fixup_label); |
| 6532 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6533 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6534 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6535 | } |
| 6536 | } |
| 6537 | |
| 6538 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6539 | Location ref, |
| 6540 | CpuRegister obj, |
| 6541 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6542 | bool needs_null_check) { |
| 6543 | DCHECK(kEmitCompilerReadBarrier); |
| 6544 | DCHECK(kUseBakerReadBarrier); |
| 6545 | |
| 6546 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6547 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6548 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6549 | } |
| 6550 | |
| 6551 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6552 | Location ref, |
| 6553 | CpuRegister obj, |
| 6554 | uint32_t data_offset, |
| 6555 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6556 | bool needs_null_check) { |
| 6557 | DCHECK(kEmitCompilerReadBarrier); |
| 6558 | DCHECK(kUseBakerReadBarrier); |
| 6559 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6560 | static_assert( |
| 6561 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6562 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6563 | // /* HeapReference<Object> */ ref = |
| 6564 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6565 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6566 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6567 | } |
| 6568 | |
| 6569 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6570 | Location ref, |
| 6571 | CpuRegister obj, |
| 6572 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6573 | bool needs_null_check, |
| 6574 | bool always_update_field, |
| 6575 | CpuRegister* temp1, |
| 6576 | CpuRegister* temp2) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6577 | DCHECK(kEmitCompilerReadBarrier); |
| 6578 | DCHECK(kUseBakerReadBarrier); |
| 6579 | |
| 6580 | // In slow path based read barriers, the read barrier call is |
| 6581 | // inserted after the original load. However, in fast path based |
| 6582 | // Baker's read barriers, we need to perform the load of |
| 6583 | // mirror::Object::monitor_ *before* the original reference load. |
| 6584 | // This load-load ordering is required by the read barrier. |
| 6585 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6586 | // |
| 6587 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6588 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6589 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6590 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6591 | // if (is_gray) { |
| 6592 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6593 | // } |
| 6594 | // |
| 6595 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6596 | // slightly more complex as: |
| 6597 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6598 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6599 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6600 | // 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] | 6601 | // - it performs additional checks that we do not do here for |
| 6602 | // performance reasons. |
| 6603 | |
| 6604 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6605 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6606 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6607 | // 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] | 6608 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6609 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6610 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6611 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6612 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6613 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6614 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6615 | // ref = ReadBarrier::Mark(ref); |
| 6616 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6617 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6618 | if (needs_null_check) { |
| 6619 | MaybeRecordImplicitNullCheck(instruction); |
| 6620 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6621 | |
| 6622 | // Load fence to prevent load-load reordering. |
| 6623 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6624 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6625 | |
| 6626 | // The actual reference load. |
| 6627 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6628 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6629 | |
| 6630 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6631 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6632 | SlowPathCode* slow_path; |
| 6633 | if (always_update_field) { |
| 6634 | DCHECK(temp1 != nullptr); |
| 6635 | DCHECK(temp2 != nullptr); |
| 6636 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
| 6637 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp1, *temp2); |
| 6638 | } else { |
| 6639 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6640 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 6641 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6642 | AddSlowPath(slow_path); |
| 6643 | |
| 6644 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6645 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6646 | |
| 6647 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6648 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6649 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6650 | __ Bind(slow_path->GetExitLabel()); |
| 6651 | } |
| 6652 | |
| 6653 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6654 | Location out, |
| 6655 | Location ref, |
| 6656 | Location obj, |
| 6657 | uint32_t offset, |
| 6658 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6659 | DCHECK(kEmitCompilerReadBarrier); |
| 6660 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6661 | // Insert a slow path based read barrier *after* the reference load. |
| 6662 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6663 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6664 | // reference will be carried out by the runtime within the slow |
| 6665 | // path. |
| 6666 | // |
| 6667 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6668 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6669 | // not used by the artReadBarrierSlow entry point. |
| 6670 | // |
| 6671 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6672 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6673 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6674 | AddSlowPath(slow_path); |
| 6675 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6676 | __ jmp(slow_path->GetEntryLabel()); |
| 6677 | __ Bind(slow_path->GetExitLabel()); |
| 6678 | } |
| 6679 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6680 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6681 | Location out, |
| 6682 | Location ref, |
| 6683 | Location obj, |
| 6684 | uint32_t offset, |
| 6685 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6686 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6687 | // Baker's read barriers shall be handled by the fast path |
| 6688 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6689 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6690 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6691 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6692 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6693 | } else if (kPoisonHeapReferences) { |
| 6694 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6695 | } |
| 6696 | } |
| 6697 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6698 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6699 | Location out, |
| 6700 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6701 | DCHECK(kEmitCompilerReadBarrier); |
| 6702 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6703 | // Insert a slow path based read barrier *after* the GC root load. |
| 6704 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6705 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6706 | // not need to do anything special for this here. |
| 6707 | SlowPathCode* slow_path = |
| 6708 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6709 | AddSlowPath(slow_path); |
| 6710 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6711 | __ jmp(slow_path->GetEntryLabel()); |
| 6712 | __ Bind(slow_path->GetExitLabel()); |
| 6713 | } |
| 6714 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6715 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6716 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6717 | LOG(FATAL) << "Unreachable"; |
| 6718 | } |
| 6719 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6720 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6721 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6722 | LOG(FATAL) << "Unreachable"; |
| 6723 | } |
| 6724 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6725 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6726 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6727 | LocationSummary* locations = |
| 6728 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6729 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6730 | locations->AddTemp(Location::RequiresRegister()); |
| 6731 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6732 | } |
| 6733 | |
| 6734 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6735 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6736 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6737 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6738 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6739 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6740 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6741 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6742 | |
| 6743 | // Should we generate smaller inline compare/jumps? |
| 6744 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6745 | // Figure out the correct compare values and jump conditions. |
| 6746 | // Handle the first compare/branch as a special case because it might |
| 6747 | // jump to the default case. |
| 6748 | DCHECK_GT(num_entries, 2u); |
| 6749 | Condition first_condition; |
| 6750 | uint32_t index; |
| 6751 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6752 | if (lower_bound != 0) { |
| 6753 | first_condition = kLess; |
| 6754 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6755 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6756 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6757 | |
| 6758 | index = 1; |
| 6759 | } else { |
| 6760 | // Handle all the compare/jumps below. |
| 6761 | first_condition = kBelow; |
| 6762 | index = 0; |
| 6763 | } |
| 6764 | |
| 6765 | // Handle the rest of the compare/jumps. |
| 6766 | for (; index + 1 < num_entries; index += 2) { |
| 6767 | int32_t compare_to_value = lower_bound + index + 1; |
| 6768 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6769 | // Jump to successors[index] if value < case_value[index]. |
| 6770 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6771 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6772 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6773 | } |
| 6774 | |
| 6775 | if (index != num_entries) { |
| 6776 | // There are an odd number of entries. Handle the last one. |
| 6777 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6778 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6779 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6780 | } |
| 6781 | |
| 6782 | // And the default for any other value. |
| 6783 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6784 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6785 | } |
| 6786 | return; |
| 6787 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6788 | |
| 6789 | // Remove the bias, if needed. |
| 6790 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6791 | if (lower_bound != 0) { |
| 6792 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6793 | value_reg_out = temp_reg.AsRegister(); |
| 6794 | } |
| 6795 | CpuRegister value_reg(value_reg_out); |
| 6796 | |
| 6797 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6798 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6799 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6800 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6801 | // We are in the range of the table. |
| 6802 | // Load the address of the jump table in the constant area. |
| 6803 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6804 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6805 | // Load the (signed) offset from the jump table. |
| 6806 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6807 | |
| 6808 | // Add the offset to the address of the table base. |
| 6809 | __ addq(temp_reg, base_reg); |
| 6810 | |
| 6811 | // And jump. |
| 6812 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6813 | } |
| 6814 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6815 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6816 | if (value == 0) { |
| 6817 | __ xorl(dest, dest); |
| 6818 | } else { |
| 6819 | __ movl(dest, Immediate(value)); |
| 6820 | } |
| 6821 | } |
| 6822 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6823 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6824 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6825 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6826 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6827 | } else if (IsUint<32>(value)) { |
| 6828 | // 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] | 6829 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6830 | } else { |
| 6831 | __ movq(dest, Immediate(value)); |
| 6832 | } |
| 6833 | } |
| 6834 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6835 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6836 | if (value == 0) { |
| 6837 | __ xorps(dest, dest); |
| 6838 | } else { |
| 6839 | __ movss(dest, LiteralInt32Address(value)); |
| 6840 | } |
| 6841 | } |
| 6842 | |
| 6843 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6844 | if (value == 0) { |
| 6845 | __ xorpd(dest, dest); |
| 6846 | } else { |
| 6847 | __ movsd(dest, LiteralInt64Address(value)); |
| 6848 | } |
| 6849 | } |
| 6850 | |
| 6851 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6852 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6853 | } |
| 6854 | |
| 6855 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6856 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6857 | } |
| 6858 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6859 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6860 | if (value == 0) { |
| 6861 | __ testl(dest, dest); |
| 6862 | } else { |
| 6863 | __ cmpl(dest, Immediate(value)); |
| 6864 | } |
| 6865 | } |
| 6866 | |
| 6867 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6868 | if (IsInt<32>(value)) { |
| 6869 | if (value == 0) { |
| 6870 | __ testq(dest, dest); |
| 6871 | } else { |
| 6872 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6873 | } |
| 6874 | } else { |
| 6875 | // Value won't fit in an int. |
| 6876 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6877 | } |
| 6878 | } |
| 6879 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6880 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 6881 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6882 | GenerateIntCompare(lhs_reg, rhs); |
| 6883 | } |
| 6884 | |
| 6885 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6886 | if (rhs.IsConstant()) { |
| 6887 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6888 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6889 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6890 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6891 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6892 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6893 | } |
| 6894 | } |
| 6895 | |
| 6896 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 6897 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 6898 | if (rhs.IsConstant()) { |
| 6899 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 6900 | Compare64BitValue(lhs_reg, value); |
| 6901 | } else if (rhs.IsDoubleStackSlot()) { |
| 6902 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 6903 | } else { |
| 6904 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 6905 | } |
| 6906 | } |
| 6907 | |
| 6908 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 6909 | Location index, |
| 6910 | ScaleFactor scale, |
| 6911 | uint32_t data_offset) { |
| 6912 | return index.IsConstant() ? |
| 6913 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 6914 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 6915 | } |
| 6916 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6917 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6918 | DCHECK(dest.IsDoubleStackSlot()); |
| 6919 | if (IsInt<32>(value)) { |
| 6920 | // Can move directly as an int32 constant. |
| 6921 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6922 | Immediate(static_cast<int32_t>(value))); |
| 6923 | } else { |
| 6924 | Load64BitValue(CpuRegister(TMP), value); |
| 6925 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6926 | } |
| 6927 | } |
| 6928 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6929 | /** |
| 6930 | * Class to handle late fixup of offsets into constant area. |
| 6931 | */ |
| 6932 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6933 | public: |
| 6934 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6935 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6936 | |
| 6937 | protected: |
| 6938 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6939 | |
| 6940 | CodeGeneratorX86_64* codegen_; |
| 6941 | |
| 6942 | private: |
| 6943 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6944 | // Patch the correct offset for the instruction. We use the address of the |
| 6945 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6946 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6947 | int32_t relative_position = constant_offset - pos; |
| 6948 | |
| 6949 | // Patch in the right value. |
| 6950 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6951 | } |
| 6952 | |
| 6953 | // Location in constant area that the fixup refers to. |
| 6954 | size_t offset_into_constant_area_; |
| 6955 | }; |
| 6956 | |
| 6957 | /** |
| 6958 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6959 | * constant area. |
| 6960 | */ |
| 6961 | class JumpTableRIPFixup : public RIPFixup { |
| 6962 | public: |
| 6963 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6964 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6965 | |
| 6966 | void CreateJumpTable() { |
| 6967 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6968 | |
| 6969 | // Ensure that the reference to the jump table has the correct offset. |
| 6970 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6971 | SetOffset(offset_in_constant_table); |
| 6972 | |
| 6973 | // Compute the offset from the start of the function to this jump table. |
| 6974 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6975 | |
| 6976 | // Populate the jump table with the correct values for the jump table. |
| 6977 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6978 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6979 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6980 | // The value that we want is the target offset - the position of the table. |
| 6981 | for (int32_t i = 0; i < num_entries; i++) { |
| 6982 | HBasicBlock* b = successors[i]; |
| 6983 | Label* l = codegen_->GetLabelOf(b); |
| 6984 | DCHECK(l->IsBound()); |
| 6985 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 6986 | assembler->AppendInt32(offset_to_block); |
| 6987 | } |
| 6988 | } |
| 6989 | |
| 6990 | private: |
| 6991 | const HPackedSwitch* switch_instr_; |
| 6992 | }; |
| 6993 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6994 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 6995 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6996 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6997 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6998 | // 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] | 6999 | assembler->Align(4, 0); |
| 7000 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7001 | |
| 7002 | // Populate any jump tables. |
| 7003 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7004 | jump_table->CreateJumpTable(); |
| 7005 | } |
| 7006 | |
| 7007 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7008 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7009 | } |
| 7010 | |
| 7011 | // And finish up. |
| 7012 | CodeGenerator::Finalize(allocator); |
| 7013 | } |
| 7014 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7015 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 7016 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7017 | return Address::RIP(fixup); |
| 7018 | } |
| 7019 | |
| 7020 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 7021 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7022 | return Address::RIP(fixup); |
| 7023 | } |
| 7024 | |
| 7025 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 7026 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7027 | return Address::RIP(fixup); |
| 7028 | } |
| 7029 | |
| 7030 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 7031 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7032 | return Address::RIP(fixup); |
| 7033 | } |
| 7034 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7035 | // TODO: trg as memory. |
| 7036 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7037 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7038 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7039 | return; |
| 7040 | } |
| 7041 | |
| 7042 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7043 | |
| 7044 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7045 | if (trg.Equals(return_loc)) { |
| 7046 | return; |
| 7047 | } |
| 7048 | |
| 7049 | // Let the parallel move resolver take care of all of this. |
| 7050 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7051 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7052 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7053 | } |
| 7054 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7055 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7056 | // Create a fixup to be used to create and address the jump table. |
| 7057 | JumpTableRIPFixup* table_fixup = |
| 7058 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7059 | |
| 7060 | // We have to populate the jump tables. |
| 7061 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7062 | return Address::RIP(table_fixup); |
| 7063 | } |
| 7064 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7065 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7066 | const Address& addr_high, |
| 7067 | int64_t v, |
| 7068 | HInstruction* instruction) { |
| 7069 | if (IsInt<32>(v)) { |
| 7070 | int32_t v_32 = v; |
| 7071 | __ movq(addr_low, Immediate(v_32)); |
| 7072 | MaybeRecordImplicitNullCheck(instruction); |
| 7073 | } else { |
| 7074 | // Didn't fit in a register. Do it in pieces. |
| 7075 | int32_t low_v = Low32Bits(v); |
| 7076 | int32_t high_v = High32Bits(v); |
| 7077 | __ movl(addr_low, Immediate(low_v)); |
| 7078 | MaybeRecordImplicitNullCheck(instruction); |
| 7079 | __ movl(addr_high, Immediate(high_v)); |
| 7080 | } |
| 7081 | } |
| 7082 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7083 | #undef __ |
| 7084 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7085 | } // namespace x86_64 |
| 7086 | } // namespace art |