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) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame^] | 202 | __ shrl(length_loc.AsRegister<CpuRegister>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 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(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 335 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 336 | : locations->Out(); |
| 337 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 338 | DCHECK(instruction_->IsCheckCast() |
| 339 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 340 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 341 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 342 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 343 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 344 | if (!is_fatal_) { |
| 345 | SaveLiveRegisters(codegen, locations); |
| 346 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 347 | |
| 348 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 349 | // move resolver. |
| 350 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 351 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 352 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 353 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 354 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 355 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 356 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 357 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 358 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 359 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 360 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 361 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 362 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 363 | } else { |
| 364 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 365 | x86_64_codegen->InvokeRuntime(kQuickCheckCast, instruction_, dex_pc, this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 366 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 367 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 368 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 369 | if (!is_fatal_) { |
| 370 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 371 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 372 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 373 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 374 | RestoreLiveRegisters(codegen, locations); |
| 375 | __ jmp(GetExitLabel()); |
| 376 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 379 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 380 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 381 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 382 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 383 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 384 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 385 | |
| 386 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 387 | }; |
| 388 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 389 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 390 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 391 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 392 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 393 | |
| 394 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 395 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 396 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 397 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 398 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 401 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 402 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 403 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 404 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 405 | }; |
| 406 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 407 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 408 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 409 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 410 | |
| 411 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 412 | LocationSummary* locations = instruction_->GetLocations(); |
| 413 | __ Bind(GetEntryLabel()); |
| 414 | SaveLiveRegisters(codegen, locations); |
| 415 | |
| 416 | InvokeRuntimeCallingConvention calling_convention; |
| 417 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 418 | parallel_move.AddMove( |
| 419 | locations->InAt(0), |
| 420 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 421 | Primitive::kPrimNot, |
| 422 | nullptr); |
| 423 | parallel_move.AddMove( |
| 424 | locations->InAt(1), |
| 425 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 426 | Primitive::kPrimInt, |
| 427 | nullptr); |
| 428 | parallel_move.AddMove( |
| 429 | locations->InAt(2), |
| 430 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 431 | Primitive::kPrimNot, |
| 432 | nullptr); |
| 433 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 434 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 435 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 436 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 437 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 438 | RestoreLiveRegisters(codegen, locations); |
| 439 | __ jmp(GetExitLabel()); |
| 440 | } |
| 441 | |
| 442 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 443 | |
| 444 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 445 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 446 | }; |
| 447 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 448 | // Slow path marking an object reference `ref` during a read |
| 449 | // barrier. The field `obj.field` in the object `obj` holding this |
| 450 | // reference does not get updated by this slow path after marking (see |
| 451 | // ReadBarrierMarkAndUpdateFieldSlowPathX86_64 below for that). |
| 452 | // |
| 453 | // This means that after the execution of this slow path, `ref` will |
| 454 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 455 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 456 | // probably still be a from-space reference (unless it gets updated by |
| 457 | // another thread, or if another thread installed another object |
| 458 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 459 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 460 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 461 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, |
| 462 | Location ref, |
| 463 | bool unpoison_ref_before_marking) |
| 464 | : SlowPathCode(instruction), |
| 465 | ref_(ref), |
| 466 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 467 | DCHECK(kEmitCompilerReadBarrier); |
| 468 | } |
| 469 | |
| 470 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 471 | |
| 472 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 473 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 474 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 475 | Register ref_reg = ref_cpu_reg.AsRegister(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 476 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 477 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 478 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 479 | instruction_->IsStaticFieldGet() || |
| 480 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 481 | instruction_->IsArraySet() || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 482 | instruction_->IsLoadClass() || |
| 483 | instruction_->IsLoadString() || |
| 484 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 485 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 486 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 487 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 488 | << "Unexpected instruction in read barrier marking slow path: " |
| 489 | << instruction_->DebugName(); |
| 490 | |
| 491 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 492 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 493 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 494 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 495 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 496 | // No need to save live registers; it's taken care of by the |
| 497 | // entrypoint. Also, there is no need to update the stack mask, |
| 498 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 499 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 500 | DCHECK_NE(ref_reg, RSP); |
| 501 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 502 | // "Compact" slow path, saving two moves. |
| 503 | // |
| 504 | // Instead of using the standard runtime calling convention (input |
| 505 | // and output in R0): |
| 506 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 507 | // RDI <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 508 | // RAX <- ReadBarrierMark(RDI) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 509 | // ref <- RAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 510 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 511 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 512 | // of a dedicated entrypoint: |
| 513 | // |
| 514 | // rX <- ReadBarrierMarkRegX(rX) |
| 515 | // |
| 516 | int32_t entry_point_offset = |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 517 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 518 | // This runtime call does not require a stack map. |
| 519 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 520 | __ jmp(GetExitLabel()); |
| 521 | } |
| 522 | |
| 523 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 524 | // The location (register) of the marked object reference. |
| 525 | const Location ref_; |
| 526 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 527 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 528 | |
| 529 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 530 | }; |
| 531 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 532 | // Slow path marking an object reference `ref` during a read barrier, |
| 533 | // and if needed, atomically updating the field `obj.field` in the |
| 534 | // object `obj` holding this reference after marking (contrary to |
| 535 | // ReadBarrierMarkSlowPathX86_64 above, which never tries to update |
| 536 | // `obj.field`). |
| 537 | // |
| 538 | // This means that after the execution of this slow path, both `ref` |
| 539 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 540 | // hold the same to-space reference (unless another thread installed |
| 541 | // another object reference (different from `ref`) in `obj.field`). |
| 542 | class ReadBarrierMarkAndUpdateFieldSlowPathX86_64 : public SlowPathCode { |
| 543 | public: |
| 544 | ReadBarrierMarkAndUpdateFieldSlowPathX86_64(HInstruction* instruction, |
| 545 | Location ref, |
| 546 | CpuRegister obj, |
| 547 | const Address& field_addr, |
| 548 | bool unpoison_ref_before_marking, |
| 549 | CpuRegister temp1, |
| 550 | CpuRegister temp2) |
| 551 | : SlowPathCode(instruction), |
| 552 | ref_(ref), |
| 553 | obj_(obj), |
| 554 | field_addr_(field_addr), |
| 555 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 556 | temp1_(temp1), |
| 557 | temp2_(temp2) { |
| 558 | DCHECK(kEmitCompilerReadBarrier); |
| 559 | } |
| 560 | |
| 561 | const char* GetDescription() const OVERRIDE { |
| 562 | return "ReadBarrierMarkAndUpdateFieldSlowPathX86_64"; |
| 563 | } |
| 564 | |
| 565 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 566 | LocationSummary* locations = instruction_->GetLocations(); |
| 567 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 568 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| 569 | DCHECK(locations->CanCall()); |
| 570 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 571 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 572 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 573 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 574 | << instruction_->DebugName(); |
| 575 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 576 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 577 | |
| 578 | __ Bind(GetEntryLabel()); |
| 579 | if (unpoison_ref_before_marking_) { |
| 580 | // Object* ref = ref_addr->AsMirrorPtr() |
| 581 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| 582 | } |
| 583 | |
| 584 | // Save the old (unpoisoned) reference. |
| 585 | __ movl(temp1_, ref_cpu_reg); |
| 586 | |
| 587 | // No need to save live registers; it's taken care of by the |
| 588 | // entrypoint. Also, there is no need to update the stack mask, |
| 589 | // as this runtime call will not trigger a garbage collection. |
| 590 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 591 | DCHECK_NE(ref_reg, RSP); |
| 592 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 593 | // "Compact" slow path, saving two moves. |
| 594 | // |
| 595 | // Instead of using the standard runtime calling convention (input |
| 596 | // and output in R0): |
| 597 | // |
| 598 | // RDI <- ref |
| 599 | // RAX <- ReadBarrierMark(RDI) |
| 600 | // ref <- RAX |
| 601 | // |
| 602 | // we just use rX (the register containing `ref`) as input and output |
| 603 | // of a dedicated entrypoint: |
| 604 | // |
| 605 | // rX <- ReadBarrierMarkRegX(rX) |
| 606 | // |
| 607 | int32_t entry_point_offset = |
| 608 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| 609 | // This runtime call does not require a stack map. |
| 610 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 611 | |
| 612 | // If the new reference is different from the old reference, |
| 613 | // update the field in the holder (`*field_addr`). |
| 614 | // |
| 615 | // Note that this field could also hold a different object, if |
| 616 | // another thread had concurrently changed it. In that case, the |
| 617 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 618 | // operation below would abort the CAS, leaving the field as-is. |
| 619 | NearLabel done; |
| 620 | __ cmpl(temp1_, ref_cpu_reg); |
| 621 | __ j(kEqual, &done); |
| 622 | |
| 623 | // Update the the holder's field atomically. This may fail if |
| 624 | // mutator updates before us, but it's OK. This is achived |
| 625 | // using a strong compare-and-set (CAS) operation with relaxed |
| 626 | // memory synchronization ordering, where the expected value is |
| 627 | // the old reference and the desired value is the new reference. |
| 628 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 629 | // instruction, which requires the expected value (the old |
| 630 | // reference) to be in EAX. Save RAX beforehand, and move the |
| 631 | // expected value (stored in `temp1_`) into EAX. |
| 632 | __ movq(temp2_, CpuRegister(RAX)); |
| 633 | __ movl(CpuRegister(RAX), temp1_); |
| 634 | |
| 635 | // Convenience aliases. |
| 636 | CpuRegister base = obj_; |
| 637 | CpuRegister expected = CpuRegister(RAX); |
| 638 | CpuRegister value = ref_cpu_reg; |
| 639 | |
| 640 | bool base_equals_value = (base.AsRegister() == value.AsRegister()); |
| 641 | Register value_reg = ref_reg; |
| 642 | if (kPoisonHeapReferences) { |
| 643 | if (base_equals_value) { |
| 644 | // If `base` and `value` are the same register location, move |
| 645 | // `value_reg` to a temporary register. This way, poisoning |
| 646 | // `value_reg` won't invalidate `base`. |
| 647 | value_reg = temp1_.AsRegister(); |
| 648 | __ movl(CpuRegister(value_reg), base); |
| 649 | } |
| 650 | |
| 651 | // Check that the register allocator did not assign the location |
| 652 | // of `expected` (RAX) to `value` nor to `base`, so that heap |
| 653 | // poisoning (when enabled) works as intended below. |
| 654 | // - If `value` were equal to `expected`, both references would |
| 655 | // be poisoned twice, meaning they would not be poisoned at |
| 656 | // all, as heap poisoning uses address negation. |
| 657 | // - If `base` were equal to `expected`, poisoning `expected` |
| 658 | // would invalidate `base`. |
| 659 | DCHECK_NE(value_reg, expected.AsRegister()); |
| 660 | DCHECK_NE(base.AsRegister(), expected.AsRegister()); |
| 661 | |
| 662 | __ PoisonHeapReference(expected); |
| 663 | __ PoisonHeapReference(CpuRegister(value_reg)); |
| 664 | } |
| 665 | |
| 666 | __ LockCmpxchgl(field_addr_, CpuRegister(value_reg)); |
| 667 | |
| 668 | // If heap poisoning is enabled, we need to unpoison the values |
| 669 | // that were poisoned earlier. |
| 670 | if (kPoisonHeapReferences) { |
| 671 | if (base_equals_value) { |
| 672 | // `value_reg` has been moved to a temporary register, no need |
| 673 | // to unpoison it. |
| 674 | } else { |
| 675 | __ UnpoisonHeapReference(CpuRegister(value_reg)); |
| 676 | } |
| 677 | // No need to unpoison `expected` (RAX), as it is be overwritten below. |
| 678 | } |
| 679 | |
| 680 | // Restore RAX. |
| 681 | __ movq(CpuRegister(RAX), temp2_); |
| 682 | |
| 683 | __ Bind(&done); |
| 684 | __ jmp(GetExitLabel()); |
| 685 | } |
| 686 | |
| 687 | private: |
| 688 | // The location (register) of the marked object reference. |
| 689 | const Location ref_; |
| 690 | // The register containing the object holding the marked object reference field. |
| 691 | const CpuRegister obj_; |
| 692 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 693 | const Address field_addr_; |
| 694 | |
| 695 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 696 | const bool unpoison_ref_before_marking_; |
| 697 | |
| 698 | const CpuRegister temp1_; |
| 699 | const CpuRegister temp2_; |
| 700 | |
| 701 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86_64); |
| 702 | }; |
| 703 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 704 | // Slow path generating a read barrier for a heap reference. |
| 705 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 706 | public: |
| 707 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 708 | Location out, |
| 709 | Location ref, |
| 710 | Location obj, |
| 711 | uint32_t offset, |
| 712 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 713 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 714 | out_(out), |
| 715 | ref_(ref), |
| 716 | obj_(obj), |
| 717 | offset_(offset), |
| 718 | index_(index) { |
| 719 | DCHECK(kEmitCompilerReadBarrier); |
| 720 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 721 | // object has been overwritten by (or after) the heap object |
| 722 | // reference load to be instrumented, e.g.: |
| 723 | // |
| 724 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 725 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 726 | // |
| 727 | // In that case, we have lost the information about the original |
| 728 | // object, and the emitted read barrier cannot work properly. |
| 729 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 730 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 731 | } |
| 732 | |
| 733 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 734 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 735 | LocationSummary* locations = instruction_->GetLocations(); |
| 736 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 737 | DCHECK(locations->CanCall()); |
| 738 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 739 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 740 | instruction_->IsStaticFieldGet() || |
| 741 | instruction_->IsArrayGet() || |
| 742 | instruction_->IsInstanceOf() || |
| 743 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 744 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 745 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 746 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 747 | |
| 748 | __ Bind(GetEntryLabel()); |
| 749 | SaveLiveRegisters(codegen, locations); |
| 750 | |
| 751 | // We may have to change the index's value, but as `index_` is a |
| 752 | // constant member (like other "inputs" of this slow path), |
| 753 | // introduce a copy of it, `index`. |
| 754 | Location index = index_; |
| 755 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 756 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 757 | if (instruction_->IsArrayGet()) { |
| 758 | // Compute real offset and store it in index_. |
| 759 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 760 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 761 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 762 | // We are about to change the value of `index_reg` (see the |
| 763 | // calls to art::x86_64::X86_64Assembler::shll and |
| 764 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 765 | // has not been saved by the previous call to |
| 766 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 767 | // callee-save register -- |
| 768 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 769 | // callee-save registers, as it has been designed with the |
| 770 | // assumption that callee-save registers are supposed to be |
| 771 | // handled by the called function. So, as a callee-save |
| 772 | // register, `index_reg` _would_ eventually be saved onto |
| 773 | // the stack, but it would be too late: we would have |
| 774 | // changed its value earlier. Therefore, we manually save |
| 775 | // it here into another freely available register, |
| 776 | // `free_reg`, chosen of course among the caller-save |
| 777 | // registers (as a callee-save `free_reg` register would |
| 778 | // exhibit the same problem). |
| 779 | // |
| 780 | // Note we could have requested a temporary register from |
| 781 | // the register allocator instead; but we prefer not to, as |
| 782 | // this is a slow path, and we know we can find a |
| 783 | // caller-save register that is available. |
| 784 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 785 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 786 | index_reg = free_reg; |
| 787 | index = Location::RegisterLocation(index_reg); |
| 788 | } else { |
| 789 | // The initial register stored in `index_` has already been |
| 790 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 791 | // (as it is not a callee-save register), so we can freely |
| 792 | // use it. |
| 793 | } |
| 794 | // Shifting the index value contained in `index_reg` by the |
| 795 | // scale factor (2) cannot overflow in practice, as the |
| 796 | // runtime is unable to allocate object arrays with a size |
| 797 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 798 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 799 | static_assert( |
| 800 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 801 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 802 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 803 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 804 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 805 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 806 | // (as in the case of ArrayGet), as it is actually an offset |
| 807 | // to an object field within an object. |
| 808 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 809 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 810 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 811 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 812 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 813 | DCHECK_EQ(offset_, 0U); |
| 814 | DCHECK(index_.IsRegister()); |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | // We're moving two or three locations to locations that could |
| 819 | // overlap, so we need a parallel move resolver. |
| 820 | InvokeRuntimeCallingConvention calling_convention; |
| 821 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 822 | parallel_move.AddMove(ref_, |
| 823 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 824 | Primitive::kPrimNot, |
| 825 | nullptr); |
| 826 | parallel_move.AddMove(obj_, |
| 827 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 828 | Primitive::kPrimNot, |
| 829 | nullptr); |
| 830 | if (index.IsValid()) { |
| 831 | parallel_move.AddMove(index, |
| 832 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 833 | Primitive::kPrimInt, |
| 834 | nullptr); |
| 835 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 836 | } else { |
| 837 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 838 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 839 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 840 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 841 | instruction_, |
| 842 | instruction_->GetDexPc(), |
| 843 | this); |
| 844 | CheckEntrypointTypes< |
| 845 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 846 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 847 | |
| 848 | RestoreLiveRegisters(codegen, locations); |
| 849 | __ jmp(GetExitLabel()); |
| 850 | } |
| 851 | |
| 852 | const char* GetDescription() const OVERRIDE { |
| 853 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 854 | } |
| 855 | |
| 856 | private: |
| 857 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 858 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 859 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 860 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 861 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 862 | return static_cast<CpuRegister>(i); |
| 863 | } |
| 864 | } |
| 865 | // We shall never fail to find a free caller-save register, as |
| 866 | // there are more than two core caller-save registers on x86-64 |
| 867 | // (meaning it is possible to find one which is different from |
| 868 | // `ref` and `obj`). |
| 869 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 870 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 871 | UNREACHABLE(); |
| 872 | } |
| 873 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 874 | const Location out_; |
| 875 | const Location ref_; |
| 876 | const Location obj_; |
| 877 | const uint32_t offset_; |
| 878 | // An additional location containing an index to an array. |
| 879 | // Only used for HArrayGet and the UnsafeGetObject & |
| 880 | // UnsafeGetObjectVolatile intrinsics. |
| 881 | const Location index_; |
| 882 | |
| 883 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 884 | }; |
| 885 | |
| 886 | // Slow path generating a read barrier for a GC root. |
| 887 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 888 | public: |
| 889 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 890 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 891 | DCHECK(kEmitCompilerReadBarrier); |
| 892 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 893 | |
| 894 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 895 | LocationSummary* locations = instruction_->GetLocations(); |
| 896 | DCHECK(locations->CanCall()); |
| 897 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 898 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 899 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 900 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 901 | |
| 902 | __ Bind(GetEntryLabel()); |
| 903 | SaveLiveRegisters(codegen, locations); |
| 904 | |
| 905 | InvokeRuntimeCallingConvention calling_convention; |
| 906 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 907 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 908 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 909 | instruction_, |
| 910 | instruction_->GetDexPc(), |
| 911 | this); |
| 912 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 913 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 914 | |
| 915 | RestoreLiveRegisters(codegen, locations); |
| 916 | __ jmp(GetExitLabel()); |
| 917 | } |
| 918 | |
| 919 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 920 | |
| 921 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 922 | const Location out_; |
| 923 | const Location root_; |
| 924 | |
| 925 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 926 | }; |
| 927 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 928 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 929 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 930 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 931 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 932 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 933 | switch (cond) { |
| 934 | case kCondEQ: return kEqual; |
| 935 | case kCondNE: return kNotEqual; |
| 936 | case kCondLT: return kLess; |
| 937 | case kCondLE: return kLessEqual; |
| 938 | case kCondGT: return kGreater; |
| 939 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 940 | case kCondB: return kBelow; |
| 941 | case kCondBE: return kBelowEqual; |
| 942 | case kCondA: return kAbove; |
| 943 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 944 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 945 | LOG(FATAL) << "Unreachable"; |
| 946 | UNREACHABLE(); |
| 947 | } |
| 948 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 949 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 950 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 951 | switch (cond) { |
| 952 | case kCondEQ: return kEqual; |
| 953 | case kCondNE: return kNotEqual; |
| 954 | case kCondLT: return kBelow; |
| 955 | case kCondLE: return kBelowEqual; |
| 956 | case kCondGT: return kAbove; |
| 957 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 958 | default: break; // should not happen |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 959 | }; |
| 960 | LOG(FATAL) << "Unreachable"; |
| 961 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 962 | } |
| 963 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 964 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 965 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 966 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 967 | switch (desired_dispatch_info.code_ptr_location) { |
| 968 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 969 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 970 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 971 | return HInvokeStaticOrDirect::DispatchInfo { |
| 972 | desired_dispatch_info.method_load_kind, |
| 973 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 974 | desired_dispatch_info.method_load_data, |
| 975 | 0u |
| 976 | }; |
| 977 | default: |
| 978 | return desired_dispatch_info; |
| 979 | } |
| 980 | } |
| 981 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 982 | Location CodeGeneratorX86_64::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 983 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 984 | // All registers are assumed to be correctly set up. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 985 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 986 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 987 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 988 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 989 | uint32_t offset = |
| 990 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 991 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 992 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 993 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 994 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 995 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 996 | break; |
| 997 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 998 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 999 | break; |
| 1000 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 1001 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1002 | method_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 1003 | invoke->GetTargetMethod().dex_method_index); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1004 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 1005 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1006 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1007 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 1008 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1009 | // Bind a new fixup label at the end of the "movl" insn. |
| 1010 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 1011 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFile(), offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1012 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1013 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1014 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1015 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1016 | Register method_reg; |
| 1017 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 1018 | if (current_method.IsRegister()) { |
| 1019 | method_reg = current_method.AsRegister<Register>(); |
| 1020 | } else { |
| 1021 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 1022 | DCHECK(!current_method.IsValid()); |
| 1023 | method_reg = reg.AsRegister(); |
| 1024 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 1025 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1026 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 1027 | __ movq(reg, |
| 1028 | Address(CpuRegister(method_reg), |
| 1029 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 1030 | // temp = temp[index_in_cache]; |
| 1031 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 1032 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1033 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 1034 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1035 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1036 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 1037 | return callee_method; |
| 1038 | } |
| 1039 | |
| 1040 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 1041 | Location temp) { |
| 1042 | // All registers are assumed to be correctly set up. |
| 1043 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1044 | |
| 1045 | switch (invoke->GetCodePtrLocation()) { |
| 1046 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 1047 | __ call(&frame_entry_label_); |
| 1048 | break; |
| 1049 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1050 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 1051 | invoke->GetTargetMethod().dex_method_index); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1052 | Label* label = &relative_call_patches_.back().label; |
| 1053 | __ call(label); // Bind to the patch label, override at link time. |
| 1054 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 1055 | break; |
| 1056 | } |
| 1057 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 1058 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 1059 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 1060 | LOG(FATAL) << "Unsupported"; |
| 1061 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1062 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 1063 | // (callee_method + offset_of_quick_compiled_code)() |
| 1064 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1065 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1066 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1067 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1068 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1069 | |
| 1070 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1071 | } |
| 1072 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1073 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 1074 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1075 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1076 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1077 | |
| 1078 | // Use the calling convention instead of the location of the receiver, as |
| 1079 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1080 | // slow path, the arguments have been moved to the right place, so here we are |
| 1081 | // guaranteed that the receiver is the first register of the calling convention. |
| 1082 | InvokeDexCallingConvention calling_convention; |
| 1083 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1084 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1085 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1086 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1087 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1088 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1089 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1090 | // emit a read barrier for the previous class reference load. |
| 1091 | // However this is not required in practice, as this is an |
| 1092 | // intermediate/temporary reference and because the current |
| 1093 | // concurrent copying collector keeps the from-space memory |
| 1094 | // intact/accessible until the end of the marking phase (the |
| 1095 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1096 | __ MaybeUnpoisonHeapReference(temp); |
| 1097 | // temp = temp->GetMethodAt(method_offset); |
| 1098 | __ movq(temp, Address(temp, method_offset)); |
| 1099 | // call temp->GetEntryPoint(); |
| 1100 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1101 | kX86_64PointerSize).SizeValue())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1104 | void CodeGeneratorX86_64::RecordSimplePatch() { |
| 1105 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 1106 | simple_patches_.emplace_back(); |
| 1107 | __ Bind(&simple_patches_.back()); |
| 1108 | } |
| 1109 | } |
| 1110 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1111 | void CodeGeneratorX86_64::RecordBootStringPatch(HLoadString* load_string) { |
| 1112 | DCHECK(GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1113 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 1114 | __ Bind(&string_patches_.back().label); |
| 1115 | } |
| 1116 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1117 | void CodeGeneratorX86_64::RecordTypePatch(HLoadClass* load_class) { |
| 1118 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 1119 | __ Bind(&type_patches_.back().label); |
| 1120 | } |
| 1121 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1122 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
| 1123 | DCHECK(!GetCompilerOptions().IsBootImage()); |
| 1124 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 1125 | return &string_patches_.back().label; |
| 1126 | } |
| 1127 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1128 | Label* CodeGeneratorX86_64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 1129 | uint32_t element_offset) { |
| 1130 | // Add a patch entry and return the label. |
| 1131 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 1132 | return &pc_relative_dex_cache_patches_.back().label; |
| 1133 | } |
| 1134 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1135 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 1136 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 1137 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 1138 | |
| 1139 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 1140 | inline void CodeGeneratorX86_64::EmitPcRelativeLinkerPatches( |
| 1141 | const ArenaDeque<PatchInfo<Label>>& infos, |
| 1142 | ArenaVector<LinkerPatch>* linker_patches) { |
| 1143 | for (const PatchInfo<Label>& info : infos) { |
| 1144 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1145 | linker_patches->push_back( |
| 1146 | Factory(literal_offset, &info.dex_file, info.label.Position(), info.index)); |
| 1147 | } |
| 1148 | } |
| 1149 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1150 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 1151 | DCHECK(linker_patches->empty()); |
| 1152 | size_t size = |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1153 | method_patches_.size() + |
| 1154 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1155 | pc_relative_dex_cache_patches_.size() + |
| 1156 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1157 | string_patches_.size() + |
| 1158 | type_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1159 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1160 | for (const PatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1161 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1162 | 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] | 1163 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1164 | for (const PatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1165 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1166 | linker_patches->push_back( |
| 1167 | LinkerPatch::RelativeCodePatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1168 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1169 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 1170 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1171 | for (const Label& label : simple_patches_) { |
| 1172 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1173 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 1174 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1175 | if (!GetCompilerOptions().IsBootImage()) { |
| 1176 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_patches_, linker_patches); |
| 1177 | } else { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1178 | // These are always PC-relative, see GetSupportedLoadStringKind(). |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1179 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1180 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1181 | // These are always PC-relative, see GetSupportedLoadClassKind(). |
| 1182 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(type_patches_, linker_patches); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1185 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1186 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1190 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1191 | } |
| 1192 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1193 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1194 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1195 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1198 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1199 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1200 | return kX86_64WordSize; |
| 1201 | } |
| 1202 | |
| 1203 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1204 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1205 | return kX86_64WordSize; |
| 1206 | } |
| 1207 | |
| 1208 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1209 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1210 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1211 | } |
| 1212 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1213 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1214 | HInstruction* instruction, |
| 1215 | uint32_t dex_pc, |
| 1216 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1217 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1218 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1219 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1220 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1221 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1222 | } |
| 1223 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1224 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1225 | HInstruction* instruction, |
| 1226 | SlowPathCode* slow_path) { |
| 1227 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1228 | GenerateInvokeRuntime(entry_point_offset); |
| 1229 | } |
| 1230 | |
| 1231 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1232 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
| 1233 | } |
| 1234 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1235 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1236 | // Use a fake return address register to mimic Quick. |
| 1237 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1238 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1239 | const X86_64InstructionSetFeatures& isa_features, |
| 1240 | const CompilerOptions& compiler_options, |
| 1241 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1242 | : CodeGenerator(graph, |
| 1243 | kNumberOfCpuRegisters, |
| 1244 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1245 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1246 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1247 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1248 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1249 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1250 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1251 | compiler_options, |
| 1252 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1253 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1254 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1255 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1256 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1257 | assembler_(graph->GetArena()), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1258 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1259 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1260 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1261 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1262 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1263 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1264 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1265 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 1266 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1267 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1268 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1269 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1270 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1271 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1272 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1273 | assembler_(codegen->GetAssembler()), |
| 1274 | codegen_(codegen) {} |
| 1275 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1276 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1277 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1278 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1279 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1280 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1281 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1282 | } |
| 1283 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1284 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1285 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1286 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1287 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1288 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1289 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1290 | } |
| 1291 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1292 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1293 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1294 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1295 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1296 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1297 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1298 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1299 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1300 | __ testq(CpuRegister(RAX), Address( |
| 1301 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1302 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1303 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1304 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1305 | if (HasEmptyFrame()) { |
| 1306 | return; |
| 1307 | } |
| 1308 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1309 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1310 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1311 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1312 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1313 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1314 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1315 | } |
| 1316 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1317 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1318 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1319 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1320 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1321 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1322 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1323 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1324 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1325 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1326 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1327 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1328 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1329 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1330 | } |
| 1331 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1332 | // Save the current method if we need it. Note that we do not |
| 1333 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1334 | // in the SSA graph. |
| 1335 | if (RequiresCurrentMethod()) { |
| 1336 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1337 | CpuRegister(kMethodRegisterArgument)); |
| 1338 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1342 | __ cfi().RememberState(); |
| 1343 | if (!HasEmptyFrame()) { |
| 1344 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1345 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1346 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1347 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1348 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1349 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1350 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1355 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1356 | __ cfi().AdjustCFAOffset(-adjust); |
| 1357 | |
| 1358 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1359 | Register reg = kCoreCalleeSaves[i]; |
| 1360 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1361 | __ popq(CpuRegister(reg)); |
| 1362 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1363 | __ cfi().Restore(DWARFReg(reg)); |
| 1364 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1365 | } |
| 1366 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1367 | __ ret(); |
| 1368 | __ cfi().RestoreState(); |
| 1369 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1370 | } |
| 1371 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1372 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1373 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1374 | } |
| 1375 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1376 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1377 | if (source.Equals(destination)) { |
| 1378 | return; |
| 1379 | } |
| 1380 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1381 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1382 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1383 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1384 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1385 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1386 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1387 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1388 | } else if (source.IsConstant()) { |
| 1389 | HConstant* constant = source.GetConstant(); |
| 1390 | if (constant->IsLongConstant()) { |
| 1391 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1392 | } else { |
| 1393 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1394 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1395 | } else { |
| 1396 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1397 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1398 | } |
| 1399 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1400 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1401 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1402 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1403 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1404 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1405 | } else if (source.IsConstant()) { |
| 1406 | HConstant* constant = source.GetConstant(); |
| 1407 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1408 | if (constant->IsFloatConstant()) { |
| 1409 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1410 | } else { |
| 1411 | Load64BitValue(dest, value); |
| 1412 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1413 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1414 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1415 | } else { |
| 1416 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1417 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1418 | } |
| 1419 | } else if (destination.IsStackSlot()) { |
| 1420 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1421 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1422 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1423 | } else if (source.IsFpuRegister()) { |
| 1424 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1425 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1426 | } else if (source.IsConstant()) { |
| 1427 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1428 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1429 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1430 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1431 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1432 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1433 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1434 | } |
| 1435 | } else { |
| 1436 | DCHECK(destination.IsDoubleStackSlot()); |
| 1437 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1438 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1439 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1440 | } else if (source.IsFpuRegister()) { |
| 1441 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1442 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1443 | } else if (source.IsConstant()) { |
| 1444 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1445 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1446 | int64_t value = GetInt64ValueOf(constant); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1447 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1448 | } else { |
| 1449 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1450 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1451 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | } |
| 1455 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1456 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1457 | DCHECK(location.IsRegister()); |
| 1458 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1459 | } |
| 1460 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1461 | void CodeGeneratorX86_64::MoveLocation( |
| 1462 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1463 | Move(dst, src); |
| 1464 | } |
| 1465 | |
| 1466 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1467 | if (location.IsRegister()) { |
| 1468 | locations->AddTemp(location); |
| 1469 | } else { |
| 1470 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1471 | } |
| 1472 | } |
| 1473 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1474 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1475 | DCHECK(!successor->IsExitBlock()); |
| 1476 | |
| 1477 | HBasicBlock* block = got->GetBlock(); |
| 1478 | HInstruction* previous = got->GetPrevious(); |
| 1479 | |
| 1480 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1481 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1482 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1483 | return; |
| 1484 | } |
| 1485 | |
| 1486 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1487 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1488 | } |
| 1489 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1490 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1491 | } |
| 1492 | } |
| 1493 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1494 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1495 | got->SetLocations(nullptr); |
| 1496 | } |
| 1497 | |
| 1498 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1499 | HandleGoto(got, got->GetSuccessor()); |
| 1500 | } |
| 1501 | |
| 1502 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1503 | try_boundary->SetLocations(nullptr); |
| 1504 | } |
| 1505 | |
| 1506 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1507 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1508 | if (!successor->IsExitBlock()) { |
| 1509 | HandleGoto(try_boundary, successor); |
| 1510 | } |
| 1511 | } |
| 1512 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1513 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1514 | exit->SetLocations(nullptr); |
| 1515 | } |
| 1516 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1517 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1518 | } |
| 1519 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1520 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1521 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1522 | LabelType* true_label, |
| 1523 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1524 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1525 | __ j(kUnordered, true_label); |
| 1526 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1527 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1528 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1529 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1530 | } |
| 1531 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1532 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1533 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1534 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1535 | Location left = locations->InAt(0); |
| 1536 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1537 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1538 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1539 | case Primitive::kPrimBoolean: |
| 1540 | case Primitive::kPrimByte: |
| 1541 | case Primitive::kPrimChar: |
| 1542 | case Primitive::kPrimShort: |
| 1543 | case Primitive::kPrimInt: |
| 1544 | case Primitive::kPrimNot: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1545 | codegen_->GenerateIntCompare(left, right); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1546 | break; |
| 1547 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1548 | case Primitive::kPrimLong: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1549 | codegen_->GenerateLongCompare(left, right); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1550 | break; |
| 1551 | } |
| 1552 | case Primitive::kPrimFloat: { |
| 1553 | if (right.IsFpuRegister()) { |
| 1554 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1555 | } else if (right.IsConstant()) { |
| 1556 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1557 | codegen_->LiteralFloatAddress( |
| 1558 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1559 | } else { |
| 1560 | DCHECK(right.IsStackSlot()); |
| 1561 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1562 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1563 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1564 | break; |
| 1565 | } |
| 1566 | case Primitive::kPrimDouble: { |
| 1567 | if (right.IsFpuRegister()) { |
| 1568 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1569 | } else if (right.IsConstant()) { |
| 1570 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1571 | codegen_->LiteralDoubleAddress( |
| 1572 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1573 | } else { |
| 1574 | DCHECK(right.IsDoubleStackSlot()); |
| 1575 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1576 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1577 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1578 | break; |
| 1579 | } |
| 1580 | default: |
| 1581 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | template<class LabelType> |
| 1586 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1587 | LabelType* true_target_in, |
| 1588 | LabelType* false_target_in) { |
| 1589 | // Generated branching requires both targets to be explicit. If either of the |
| 1590 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1591 | LabelType fallthrough_target; |
| 1592 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1593 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1594 | |
| 1595 | // Generate the comparison to set the CC. |
| 1596 | GenerateCompareTest(condition); |
| 1597 | |
| 1598 | // Now generate the correct jump(s). |
| 1599 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1600 | switch (type) { |
| 1601 | case Primitive::kPrimLong: { |
| 1602 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1603 | break; |
| 1604 | } |
| 1605 | case Primitive::kPrimFloat: { |
| 1606 | GenerateFPJumps(condition, true_target, false_target); |
| 1607 | break; |
| 1608 | } |
| 1609 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1610 | GenerateFPJumps(condition, true_target, false_target); |
| 1611 | break; |
| 1612 | } |
| 1613 | default: |
| 1614 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1615 | } |
| 1616 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1617 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1618 | __ jmp(false_target); |
| 1619 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1620 | |
| 1621 | if (fallthrough_target.IsLinked()) { |
| 1622 | __ Bind(&fallthrough_target); |
| 1623 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1624 | } |
| 1625 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1626 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1627 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1628 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1629 | // conditions if they are materialized due to the complex branching. |
| 1630 | return cond->IsCondition() && |
| 1631 | cond->GetNext() == branch && |
| 1632 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1633 | } |
| 1634 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1635 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1636 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1637 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1638 | LabelType* true_target, |
| 1639 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1640 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1641 | |
| 1642 | if (true_target == nullptr && false_target == nullptr) { |
| 1643 | // Nothing to do. The code always falls through. |
| 1644 | return; |
| 1645 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1646 | // Constant condition, statically compared against "true" (integer value 1). |
| 1647 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1648 | if (true_target != nullptr) { |
| 1649 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1650 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1651 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1652 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1653 | if (false_target != nullptr) { |
| 1654 | __ jmp(false_target); |
| 1655 | } |
| 1656 | } |
| 1657 | return; |
| 1658 | } |
| 1659 | |
| 1660 | // The following code generates these patterns: |
| 1661 | // (1) true_target == nullptr && false_target != nullptr |
| 1662 | // - opposite condition true => branch to false_target |
| 1663 | // (2) true_target != nullptr && false_target == nullptr |
| 1664 | // - condition true => branch to true_target |
| 1665 | // (3) true_target != nullptr && false_target != nullptr |
| 1666 | // - condition true => branch to true_target |
| 1667 | // - branch to false_target |
| 1668 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1669 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1670 | if (true_target == nullptr) { |
| 1671 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1672 | } else { |
| 1673 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1674 | } |
| 1675 | } else { |
| 1676 | // Materialized condition, compare against 0. |
| 1677 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1678 | if (lhs.IsRegister()) { |
| 1679 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1680 | } else { |
| 1681 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1682 | } |
| 1683 | if (true_target == nullptr) { |
| 1684 | __ j(kEqual, false_target); |
| 1685 | } else { |
| 1686 | __ j(kNotEqual, true_target); |
| 1687 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1688 | } |
| 1689 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1690 | // Condition has not been materialized, use its inputs as the |
| 1691 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1692 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1693 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1694 | // If this is a long or FP comparison that has been folded into |
| 1695 | // the HCondition, generate the comparison directly. |
| 1696 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1697 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1698 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1699 | return; |
| 1700 | } |
| 1701 | |
| 1702 | Location lhs = condition->GetLocations()->InAt(0); |
| 1703 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1704 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1705 | if (true_target == nullptr) { |
| 1706 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1707 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1708 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1709 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1710 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1711 | |
| 1712 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1713 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1714 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1715 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1716 | } |
| 1717 | } |
| 1718 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1719 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1720 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1721 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1722 | locations->SetInAt(0, Location::Any()); |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1727 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1728 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1729 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1730 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1731 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1732 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1733 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1737 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1738 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1739 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1740 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1741 | locations->SetInAt(0, Location::Any()); |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1746 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1747 | GenerateTestAndBranch<Label>(deoptimize, |
| 1748 | /* condition_input_index */ 0, |
| 1749 | slow_path->GetEntryLabel(), |
| 1750 | /* false_target */ nullptr); |
| 1751 | } |
| 1752 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1753 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1754 | // There are no conditional move instructions for XMMs. |
| 1755 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1756 | return false; |
| 1757 | } |
| 1758 | |
| 1759 | // A FP condition doesn't generate the single CC that we need. |
| 1760 | HInstruction* condition = select->GetCondition(); |
| 1761 | if (condition->IsCondition() && |
| 1762 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1763 | return false; |
| 1764 | } |
| 1765 | |
| 1766 | // We can generate a CMOV for this Select. |
| 1767 | return true; |
| 1768 | } |
| 1769 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1770 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1771 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1772 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1773 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1774 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1775 | } else { |
| 1776 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1777 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1778 | if (select->InputAt(1)->IsConstant()) { |
| 1779 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1780 | } else { |
| 1781 | locations->SetInAt(1, Location::Any()); |
| 1782 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1783 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1784 | locations->SetInAt(1, Location::Any()); |
| 1785 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1786 | } |
| 1787 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1788 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1789 | } |
| 1790 | locations->SetOut(Location::SameAsFirstInput()); |
| 1791 | } |
| 1792 | |
| 1793 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1794 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1795 | if (SelectCanUseCMOV(select)) { |
| 1796 | // If both the condition and the source types are integer, we can generate |
| 1797 | // a CMOV to implement Select. |
| 1798 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1799 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1800 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1801 | |
| 1802 | HInstruction* select_condition = select->GetCondition(); |
| 1803 | Condition cond = kNotEqual; |
| 1804 | |
| 1805 | // Figure out how to test the 'condition'. |
| 1806 | if (select_condition->IsCondition()) { |
| 1807 | HCondition* condition = select_condition->AsCondition(); |
| 1808 | if (!condition->IsEmittedAtUseSite()) { |
| 1809 | // This was a previously materialized condition. |
| 1810 | // Can we use the existing condition code? |
| 1811 | if (AreEflagsSetFrom(condition, select)) { |
| 1812 | // Materialization was the previous instruction. Condition codes are right. |
| 1813 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1814 | } else { |
| 1815 | // No, we have to recreate the condition code. |
| 1816 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1817 | __ testl(cond_reg, cond_reg); |
| 1818 | } |
| 1819 | } else { |
| 1820 | GenerateCompareTest(condition); |
| 1821 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1822 | } |
| 1823 | } else { |
| 1824 | // Must be a boolean condition, which needs to be compared to 0. |
| 1825 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1826 | __ testl(cond_reg, cond_reg); |
| 1827 | } |
| 1828 | |
| 1829 | // If the condition is true, overwrite the output, which already contains false. |
| 1830 | // Generate the correct sized CMOV. |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1831 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1832 | if (value_true_loc.IsRegister()) { |
| 1833 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1834 | } else { |
| 1835 | __ cmov(cond, |
| 1836 | value_false, |
| 1837 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1838 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1839 | } else { |
| 1840 | NearLabel false_target; |
| 1841 | GenerateTestAndBranch<NearLabel>(select, |
| 1842 | /* condition_input_index */ 2, |
| 1843 | /* true_target */ nullptr, |
| 1844 | &false_target); |
| 1845 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1846 | __ Bind(&false_target); |
| 1847 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1850 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1851 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1852 | } |
| 1853 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1854 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1855 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | void CodeGeneratorX86_64::GenerateNop() { |
| 1859 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1862 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1863 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1864 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1865 | // Handle the long/FP comparisons made in instruction simplification. |
| 1866 | switch (cond->InputAt(0)->GetType()) { |
| 1867 | case Primitive::kPrimLong: |
| 1868 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1869 | locations->SetInAt(1, Location::Any()); |
| 1870 | break; |
| 1871 | case Primitive::kPrimFloat: |
| 1872 | case Primitive::kPrimDouble: |
| 1873 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1874 | locations->SetInAt(1, Location::Any()); |
| 1875 | break; |
| 1876 | default: |
| 1877 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1878 | locations->SetInAt(1, Location::Any()); |
| 1879 | break; |
| 1880 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1881 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1882 | locations->SetOut(Location::RequiresRegister()); |
| 1883 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1884 | } |
| 1885 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1886 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1887 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1888 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1889 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1890 | |
| 1891 | LocationSummary* locations = cond->GetLocations(); |
| 1892 | Location lhs = locations->InAt(0); |
| 1893 | Location rhs = locations->InAt(1); |
| 1894 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1895 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1896 | |
| 1897 | switch (cond->InputAt(0)->GetType()) { |
| 1898 | default: |
| 1899 | // Integer case. |
| 1900 | |
| 1901 | // Clear output register: setcc only sets the low byte. |
| 1902 | __ xorl(reg, reg); |
| 1903 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1904 | codegen_->GenerateIntCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1905 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1906 | return; |
| 1907 | case Primitive::kPrimLong: |
| 1908 | // Clear output register: setcc only sets the low byte. |
| 1909 | __ xorl(reg, reg); |
| 1910 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1911 | codegen_->GenerateLongCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1912 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1913 | return; |
| 1914 | case Primitive::kPrimFloat: { |
| 1915 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1916 | if (rhs.IsConstant()) { |
| 1917 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1918 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1919 | } else if (rhs.IsStackSlot()) { |
| 1920 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1921 | } else { |
| 1922 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1923 | } |
| 1924 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1925 | break; |
| 1926 | } |
| 1927 | case Primitive::kPrimDouble: { |
| 1928 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1929 | if (rhs.IsConstant()) { |
| 1930 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1931 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1932 | } else if (rhs.IsDoubleStackSlot()) { |
| 1933 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1934 | } else { |
| 1935 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1936 | } |
| 1937 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1938 | break; |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1943 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1944 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1945 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1946 | __ Bind(&false_label); |
| 1947 | __ xorl(reg, reg); |
| 1948 | __ jmp(&done_label); |
| 1949 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1950 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1951 | __ Bind(&true_label); |
| 1952 | __ movl(reg, Immediate(1)); |
| 1953 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1957 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1961 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1965 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1969 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1973 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1977 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1981 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1985 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1989 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1993 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1997 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2001 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2002 | } |
| 2003 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2004 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2005 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2009 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2013 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2017 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2021 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2025 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2029 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2033 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2036 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2037 | LocationSummary* locations = |
| 2038 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2039 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2040 | case Primitive::kPrimBoolean: |
| 2041 | case Primitive::kPrimByte: |
| 2042 | case Primitive::kPrimShort: |
| 2043 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2044 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2045 | case Primitive::kPrimLong: { |
| 2046 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2047 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2048 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2049 | break; |
| 2050 | } |
| 2051 | case Primitive::kPrimFloat: |
| 2052 | case Primitive::kPrimDouble: { |
| 2053 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2054 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2055 | locations->SetOut(Location::RequiresRegister()); |
| 2056 | break; |
| 2057 | } |
| 2058 | default: |
| 2059 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2060 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2064 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2065 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2066 | Location left = locations->InAt(0); |
| 2067 | Location right = locations->InAt(1); |
| 2068 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2069 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2070 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2071 | Condition less_cond = kLess; |
| 2072 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2073 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 2074 | case Primitive::kPrimBoolean: |
| 2075 | case Primitive::kPrimByte: |
| 2076 | case Primitive::kPrimShort: |
| 2077 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2078 | case Primitive::kPrimInt: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2079 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2080 | break; |
| 2081 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2082 | case Primitive::kPrimLong: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2083 | codegen_->GenerateLongCompare(left, right); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2084 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2085 | } |
| 2086 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2087 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2088 | if (right.IsConstant()) { |
| 2089 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2090 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2091 | } else if (right.IsStackSlot()) { |
| 2092 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2093 | } else { |
| 2094 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2095 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2096 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2097 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2098 | break; |
| 2099 | } |
| 2100 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2101 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2102 | if (right.IsConstant()) { |
| 2103 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2104 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2105 | } else if (right.IsDoubleStackSlot()) { |
| 2106 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2107 | } else { |
| 2108 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2109 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2110 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2111 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2112 | break; |
| 2113 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2114 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2115 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2116 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2117 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2118 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2119 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2120 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2121 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2122 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2123 | __ movl(out, Immediate(1)); |
| 2124 | __ jmp(&done); |
| 2125 | |
| 2126 | __ Bind(&less); |
| 2127 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2128 | |
| 2129 | __ Bind(&done); |
| 2130 | } |
| 2131 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2132 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2133 | LocationSummary* locations = |
| 2134 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2135 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2136 | } |
| 2137 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2138 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2139 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2140 | } |
| 2141 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2142 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2143 | LocationSummary* locations = |
| 2144 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2145 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2146 | } |
| 2147 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2148 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2149 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2152 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2153 | LocationSummary* locations = |
| 2154 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2155 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2156 | } |
| 2157 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2158 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2159 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2162 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2163 | LocationSummary* locations = |
| 2164 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2165 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2166 | } |
| 2167 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2168 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2169 | // Will be generated at use site. |
| 2170 | } |
| 2171 | |
| 2172 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2173 | LocationSummary* locations = |
| 2174 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2175 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2176 | } |
| 2177 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2178 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2179 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2180 | // Will be generated at use site. |
| 2181 | } |
| 2182 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2183 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2184 | memory_barrier->SetLocations(nullptr); |
| 2185 | } |
| 2186 | |
| 2187 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2188 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2189 | } |
| 2190 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2191 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2192 | ret->SetLocations(nullptr); |
| 2193 | } |
| 2194 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2195 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2196 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2200 | LocationSummary* locations = |
| 2201 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2202 | switch (ret->InputAt(0)->GetType()) { |
| 2203 | case Primitive::kPrimBoolean: |
| 2204 | case Primitive::kPrimByte: |
| 2205 | case Primitive::kPrimChar: |
| 2206 | case Primitive::kPrimShort: |
| 2207 | case Primitive::kPrimInt: |
| 2208 | case Primitive::kPrimNot: |
| 2209 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2210 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2211 | break; |
| 2212 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2213 | case Primitive::kPrimFloat: |
| 2214 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2215 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2216 | break; |
| 2217 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2218 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2219 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2220 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2224 | if (kIsDebugBuild) { |
| 2225 | switch (ret->InputAt(0)->GetType()) { |
| 2226 | case Primitive::kPrimBoolean: |
| 2227 | case Primitive::kPrimByte: |
| 2228 | case Primitive::kPrimChar: |
| 2229 | case Primitive::kPrimShort: |
| 2230 | case Primitive::kPrimInt: |
| 2231 | case Primitive::kPrimNot: |
| 2232 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2233 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2234 | break; |
| 2235 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2236 | case Primitive::kPrimFloat: |
| 2237 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2238 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2239 | XMM0); |
| 2240 | break; |
| 2241 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2242 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2243 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2244 | } |
| 2245 | } |
| 2246 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2247 | } |
| 2248 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2249 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2250 | switch (type) { |
| 2251 | case Primitive::kPrimBoolean: |
| 2252 | case Primitive::kPrimByte: |
| 2253 | case Primitive::kPrimChar: |
| 2254 | case Primitive::kPrimShort: |
| 2255 | case Primitive::kPrimInt: |
| 2256 | case Primitive::kPrimNot: |
| 2257 | case Primitive::kPrimLong: |
| 2258 | return Location::RegisterLocation(RAX); |
| 2259 | |
| 2260 | case Primitive::kPrimVoid: |
| 2261 | return Location::NoLocation(); |
| 2262 | |
| 2263 | case Primitive::kPrimDouble: |
| 2264 | case Primitive::kPrimFloat: |
| 2265 | return Location::FpuRegisterLocation(XMM0); |
| 2266 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2267 | |
| 2268 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2272 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2273 | } |
| 2274 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2275 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2276 | switch (type) { |
| 2277 | case Primitive::kPrimBoolean: |
| 2278 | case Primitive::kPrimByte: |
| 2279 | case Primitive::kPrimChar: |
| 2280 | case Primitive::kPrimShort: |
| 2281 | case Primitive::kPrimInt: |
| 2282 | case Primitive::kPrimNot: { |
| 2283 | uint32_t index = gp_index_++; |
| 2284 | stack_index_++; |
| 2285 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2286 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2287 | } else { |
| 2288 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | case Primitive::kPrimLong: { |
| 2293 | uint32_t index = gp_index_; |
| 2294 | stack_index_ += 2; |
| 2295 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2296 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2297 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2298 | } else { |
| 2299 | gp_index_ += 2; |
| 2300 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2301 | } |
| 2302 | } |
| 2303 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2304 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2305 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2306 | stack_index_++; |
| 2307 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2308 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2309 | } else { |
| 2310 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2311 | } |
| 2312 | } |
| 2313 | |
| 2314 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2315 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2316 | stack_index_ += 2; |
| 2317 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2318 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2319 | } else { |
| 2320 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2321 | } |
| 2322 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2323 | |
| 2324 | case Primitive::kPrimVoid: |
| 2325 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2326 | break; |
| 2327 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2328 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2329 | } |
| 2330 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2331 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2332 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2333 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2334 | // the method_idx. |
| 2335 | HandleInvoke(invoke); |
| 2336 | } |
| 2337 | |
| 2338 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2339 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2340 | } |
| 2341 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2342 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2343 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2344 | // art::PrepareForRegisterAllocation. |
| 2345 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2346 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2347 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2348 | if (intrinsic.TryDispatch(invoke)) { |
| 2349 | return; |
| 2350 | } |
| 2351 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2352 | HandleInvoke(invoke); |
| 2353 | } |
| 2354 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2355 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2356 | if (invoke->GetLocations()->Intrinsified()) { |
| 2357 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2358 | intrinsic.Dispatch(invoke); |
| 2359 | return true; |
| 2360 | } |
| 2361 | return false; |
| 2362 | } |
| 2363 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2364 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2365 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2366 | // art::PrepareForRegisterAllocation. |
| 2367 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2368 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2369 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2370 | return; |
| 2371 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2372 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2373 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2374 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2375 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2376 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2377 | } |
| 2378 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2379 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2380 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2381 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2382 | } |
| 2383 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2384 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2385 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2386 | if (intrinsic.TryDispatch(invoke)) { |
| 2387 | return; |
| 2388 | } |
| 2389 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2390 | HandleInvoke(invoke); |
| 2391 | } |
| 2392 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2393 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2394 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2395 | return; |
| 2396 | } |
| 2397 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2398 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2399 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2400 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2401 | } |
| 2402 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2403 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2404 | HandleInvoke(invoke); |
| 2405 | // Add the hidden argument. |
| 2406 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2407 | } |
| 2408 | |
| 2409 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2410 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2411 | LocationSummary* locations = invoke->GetLocations(); |
| 2412 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2413 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2414 | Location receiver = locations->InAt(0); |
| 2415 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2416 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2417 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2418 | // won't be modified thereafter, before the `call` instruction. |
| 2419 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2420 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2421 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2422 | if (receiver.IsStackSlot()) { |
| 2423 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2424 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2425 | __ movl(temp, Address(temp, class_offset)); |
| 2426 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2427 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2428 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2429 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2430 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2431 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2432 | // emit a read barrier for the previous class reference load. |
| 2433 | // However this is not required in practice, as this is an |
| 2434 | // intermediate/temporary reference and because the current |
| 2435 | // concurrent copying collector keeps the from-space memory |
| 2436 | // intact/accessible until the end of the marking phase (the |
| 2437 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2438 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2439 | // temp = temp->GetAddressOfIMT() |
| 2440 | __ movq(temp, |
| 2441 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2442 | // temp = temp->GetImtEntryAt(method_offset); |
| 2443 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2444 | invoke->GetImtIndex(), kX86_64PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2445 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2446 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2447 | // call temp->GetEntryPoint(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2448 | __ call(Address( |
| 2449 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2450 | |
| 2451 | DCHECK(!codegen_->IsLeafMethod()); |
| 2452 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2453 | } |
| 2454 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2455 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2456 | LocationSummary* locations = |
| 2457 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2458 | switch (neg->GetResultType()) { |
| 2459 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2460 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2461 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2462 | locations->SetOut(Location::SameAsFirstInput()); |
| 2463 | break; |
| 2464 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2465 | case Primitive::kPrimFloat: |
| 2466 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2467 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2468 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2469 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2470 | break; |
| 2471 | |
| 2472 | default: |
| 2473 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2474 | } |
| 2475 | } |
| 2476 | |
| 2477 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2478 | LocationSummary* locations = neg->GetLocations(); |
| 2479 | Location out = locations->Out(); |
| 2480 | Location in = locations->InAt(0); |
| 2481 | switch (neg->GetResultType()) { |
| 2482 | case Primitive::kPrimInt: |
| 2483 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2484 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2485 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2486 | break; |
| 2487 | |
| 2488 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2489 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2490 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2491 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2492 | break; |
| 2493 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2494 | case Primitive::kPrimFloat: { |
| 2495 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2496 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2497 | // Implement float negation with an exclusive or with value |
| 2498 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2499 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2500 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2501 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2502 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2503 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2504 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2505 | case Primitive::kPrimDouble: { |
| 2506 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2507 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2508 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2509 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2510 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2511 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2512 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2513 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2514 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2515 | |
| 2516 | default: |
| 2517 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2518 | } |
| 2519 | } |
| 2520 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2521 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2522 | LocationSummary* locations = |
| 2523 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2524 | Primitive::Type result_type = conversion->GetResultType(); |
| 2525 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2526 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2527 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2528 | // The Java language does not allow treating boolean as an integral type but |
| 2529 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2530 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2531 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2532 | case Primitive::kPrimByte: |
| 2533 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2534 | case Primitive::kPrimLong: |
| 2535 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2536 | case Primitive::kPrimBoolean: |
| 2537 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2538 | case Primitive::kPrimShort: |
| 2539 | case Primitive::kPrimInt: |
| 2540 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2541 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2542 | locations->SetInAt(0, Location::Any()); |
| 2543 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2544 | break; |
| 2545 | |
| 2546 | default: |
| 2547 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2548 | << " to " << result_type; |
| 2549 | } |
| 2550 | break; |
| 2551 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2552 | case Primitive::kPrimShort: |
| 2553 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2554 | case Primitive::kPrimLong: |
| 2555 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2556 | case Primitive::kPrimBoolean: |
| 2557 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2558 | case Primitive::kPrimByte: |
| 2559 | case Primitive::kPrimInt: |
| 2560 | case Primitive::kPrimChar: |
| 2561 | // Processing a Dex `int-to-short' instruction. |
| 2562 | locations->SetInAt(0, Location::Any()); |
| 2563 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2564 | break; |
| 2565 | |
| 2566 | default: |
| 2567 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2568 | << " to " << result_type; |
| 2569 | } |
| 2570 | break; |
| 2571 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2572 | case Primitive::kPrimInt: |
| 2573 | switch (input_type) { |
| 2574 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2575 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2576 | locations->SetInAt(0, Location::Any()); |
| 2577 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2578 | break; |
| 2579 | |
| 2580 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2581 | // Processing a Dex `float-to-int' instruction. |
| 2582 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2583 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2584 | break; |
| 2585 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2586 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2587 | // Processing a Dex `double-to-int' instruction. |
| 2588 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2589 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2590 | break; |
| 2591 | |
| 2592 | default: |
| 2593 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2594 | << " to " << result_type; |
| 2595 | } |
| 2596 | break; |
| 2597 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2598 | case Primitive::kPrimLong: |
| 2599 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2600 | case Primitive::kPrimBoolean: |
| 2601 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2602 | case Primitive::kPrimByte: |
| 2603 | case Primitive::kPrimShort: |
| 2604 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2605 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2606 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2607 | // TODO: We would benefit from a (to-be-implemented) |
| 2608 | // Location::RegisterOrStackSlot requirement for this input. |
| 2609 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2610 | locations->SetOut(Location::RequiresRegister()); |
| 2611 | break; |
| 2612 | |
| 2613 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2614 | // Processing a Dex `float-to-long' instruction. |
| 2615 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2616 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2617 | break; |
| 2618 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2619 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2620 | // Processing a Dex `double-to-long' instruction. |
| 2621 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2622 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2623 | break; |
| 2624 | |
| 2625 | default: |
| 2626 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2627 | << " to " << result_type; |
| 2628 | } |
| 2629 | break; |
| 2630 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2631 | case Primitive::kPrimChar: |
| 2632 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2633 | case Primitive::kPrimLong: |
| 2634 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2635 | case Primitive::kPrimBoolean: |
| 2636 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2637 | case Primitive::kPrimByte: |
| 2638 | case Primitive::kPrimShort: |
| 2639 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2640 | // Processing a Dex `int-to-char' instruction. |
| 2641 | locations->SetInAt(0, Location::Any()); |
| 2642 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2643 | break; |
| 2644 | |
| 2645 | default: |
| 2646 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2647 | << " to " << result_type; |
| 2648 | } |
| 2649 | break; |
| 2650 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2651 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2652 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2653 | case Primitive::kPrimBoolean: |
| 2654 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2655 | case Primitive::kPrimByte: |
| 2656 | case Primitive::kPrimShort: |
| 2657 | case Primitive::kPrimInt: |
| 2658 | case Primitive::kPrimChar: |
| 2659 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2660 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2661 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2662 | break; |
| 2663 | |
| 2664 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2665 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2666 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2667 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2668 | break; |
| 2669 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2670 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2671 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2672 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2673 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2674 | break; |
| 2675 | |
| 2676 | default: |
| 2677 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2678 | << " to " << result_type; |
| 2679 | }; |
| 2680 | break; |
| 2681 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2682 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2683 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2684 | case Primitive::kPrimBoolean: |
| 2685 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2686 | case Primitive::kPrimByte: |
| 2687 | case Primitive::kPrimShort: |
| 2688 | case Primitive::kPrimInt: |
| 2689 | case Primitive::kPrimChar: |
| 2690 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2691 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2692 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2693 | break; |
| 2694 | |
| 2695 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2696 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2697 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2698 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2699 | break; |
| 2700 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2701 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2702 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2703 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2704 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2705 | break; |
| 2706 | |
| 2707 | default: |
| 2708 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2709 | << " to " << result_type; |
| 2710 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2711 | break; |
| 2712 | |
| 2713 | default: |
| 2714 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2715 | << " to " << result_type; |
| 2716 | } |
| 2717 | } |
| 2718 | |
| 2719 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2720 | LocationSummary* locations = conversion->GetLocations(); |
| 2721 | Location out = locations->Out(); |
| 2722 | Location in = locations->InAt(0); |
| 2723 | Primitive::Type result_type = conversion->GetResultType(); |
| 2724 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2725 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2726 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2727 | case Primitive::kPrimByte: |
| 2728 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2729 | case Primitive::kPrimLong: |
| 2730 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2731 | case Primitive::kPrimBoolean: |
| 2732 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2733 | case Primitive::kPrimShort: |
| 2734 | case Primitive::kPrimInt: |
| 2735 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2736 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2737 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2738 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2739 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2740 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2741 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2742 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2743 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2744 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2745 | } |
| 2746 | break; |
| 2747 | |
| 2748 | default: |
| 2749 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2750 | << " to " << result_type; |
| 2751 | } |
| 2752 | break; |
| 2753 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2754 | case Primitive::kPrimShort: |
| 2755 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2756 | case Primitive::kPrimLong: |
| 2757 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2758 | case Primitive::kPrimBoolean: |
| 2759 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2760 | case Primitive::kPrimByte: |
| 2761 | case Primitive::kPrimInt: |
| 2762 | case Primitive::kPrimChar: |
| 2763 | // Processing a Dex `int-to-short' instruction. |
| 2764 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2765 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2766 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2767 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2768 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2769 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2770 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2771 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2772 | } |
| 2773 | break; |
| 2774 | |
| 2775 | default: |
| 2776 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2777 | << " to " << result_type; |
| 2778 | } |
| 2779 | break; |
| 2780 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2781 | case Primitive::kPrimInt: |
| 2782 | switch (input_type) { |
| 2783 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2784 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2785 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2786 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2787 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2788 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2789 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2790 | } else { |
| 2791 | DCHECK(in.IsConstant()); |
| 2792 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2793 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2794 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2795 | } |
| 2796 | break; |
| 2797 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2798 | case Primitive::kPrimFloat: { |
| 2799 | // Processing a Dex `float-to-int' instruction. |
| 2800 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2801 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2802 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2803 | |
| 2804 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2805 | // if input >= (float)INT_MAX goto done |
| 2806 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2807 | __ j(kAboveEqual, &done); |
| 2808 | // if input == NaN goto nan |
| 2809 | __ j(kUnordered, &nan); |
| 2810 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2811 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2812 | __ jmp(&done); |
| 2813 | __ Bind(&nan); |
| 2814 | // output = 0 |
| 2815 | __ xorl(output, output); |
| 2816 | __ Bind(&done); |
| 2817 | break; |
| 2818 | } |
| 2819 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2820 | case Primitive::kPrimDouble: { |
| 2821 | // Processing a Dex `double-to-int' instruction. |
| 2822 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2823 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2824 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2825 | |
| 2826 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2827 | // if input >= (double)INT_MAX goto done |
| 2828 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2829 | __ j(kAboveEqual, &done); |
| 2830 | // if input == NaN goto nan |
| 2831 | __ j(kUnordered, &nan); |
| 2832 | // output = double-to-int-truncate(input) |
| 2833 | __ cvttsd2si(output, input); |
| 2834 | __ jmp(&done); |
| 2835 | __ Bind(&nan); |
| 2836 | // output = 0 |
| 2837 | __ xorl(output, output); |
| 2838 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2839 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2840 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2841 | |
| 2842 | default: |
| 2843 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2844 | << " to " << result_type; |
| 2845 | } |
| 2846 | break; |
| 2847 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2848 | case Primitive::kPrimLong: |
| 2849 | switch (input_type) { |
| 2850 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2851 | case Primitive::kPrimBoolean: |
| 2852 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2853 | case Primitive::kPrimByte: |
| 2854 | case Primitive::kPrimShort: |
| 2855 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2856 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2857 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2858 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2859 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2860 | break; |
| 2861 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2862 | case Primitive::kPrimFloat: { |
| 2863 | // Processing a Dex `float-to-long' instruction. |
| 2864 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2865 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2866 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2867 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2868 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2869 | // if input >= (float)LONG_MAX goto done |
| 2870 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2871 | __ j(kAboveEqual, &done); |
| 2872 | // if input == NaN goto nan |
| 2873 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2874 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2875 | __ cvttss2si(output, input, true); |
| 2876 | __ jmp(&done); |
| 2877 | __ Bind(&nan); |
| 2878 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2879 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2880 | __ Bind(&done); |
| 2881 | break; |
| 2882 | } |
| 2883 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2884 | case Primitive::kPrimDouble: { |
| 2885 | // Processing a Dex `double-to-long' instruction. |
| 2886 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2887 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2888 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2889 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2890 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2891 | // if input >= (double)LONG_MAX goto done |
| 2892 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2893 | __ j(kAboveEqual, &done); |
| 2894 | // if input == NaN goto nan |
| 2895 | __ j(kUnordered, &nan); |
| 2896 | // output = double-to-long-truncate(input) |
| 2897 | __ cvttsd2si(output, input, true); |
| 2898 | __ jmp(&done); |
| 2899 | __ Bind(&nan); |
| 2900 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2901 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2902 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2903 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2904 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2905 | |
| 2906 | default: |
| 2907 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2908 | << " to " << result_type; |
| 2909 | } |
| 2910 | break; |
| 2911 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2912 | case Primitive::kPrimChar: |
| 2913 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2914 | case Primitive::kPrimLong: |
| 2915 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2916 | case Primitive::kPrimBoolean: |
| 2917 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2918 | case Primitive::kPrimByte: |
| 2919 | case Primitive::kPrimShort: |
| 2920 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2921 | // Processing a Dex `int-to-char' instruction. |
| 2922 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2923 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2924 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2925 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2926 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2927 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2928 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2929 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2930 | } |
| 2931 | break; |
| 2932 | |
| 2933 | default: |
| 2934 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2935 | << " to " << result_type; |
| 2936 | } |
| 2937 | break; |
| 2938 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2939 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2940 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2941 | case Primitive::kPrimBoolean: |
| 2942 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2943 | case Primitive::kPrimByte: |
| 2944 | case Primitive::kPrimShort: |
| 2945 | case Primitive::kPrimInt: |
| 2946 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2947 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2948 | if (in.IsRegister()) { |
| 2949 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2950 | } else if (in.IsConstant()) { |
| 2951 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2952 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2953 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2954 | } else { |
| 2955 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2956 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2957 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2958 | break; |
| 2959 | |
| 2960 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2961 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2962 | if (in.IsRegister()) { |
| 2963 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2964 | } else if (in.IsConstant()) { |
| 2965 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2966 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2967 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2968 | } else { |
| 2969 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2970 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2971 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2972 | break; |
| 2973 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2974 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2975 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2976 | if (in.IsFpuRegister()) { |
| 2977 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2978 | } else if (in.IsConstant()) { |
| 2979 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2980 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2981 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2982 | } else { |
| 2983 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2984 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2985 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2986 | break; |
| 2987 | |
| 2988 | default: |
| 2989 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2990 | << " to " << result_type; |
| 2991 | }; |
| 2992 | break; |
| 2993 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2994 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2995 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2996 | case Primitive::kPrimBoolean: |
| 2997 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2998 | case Primitive::kPrimByte: |
| 2999 | case Primitive::kPrimShort: |
| 3000 | case Primitive::kPrimInt: |
| 3001 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3002 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3003 | if (in.IsRegister()) { |
| 3004 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3005 | } else if (in.IsConstant()) { |
| 3006 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3007 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3008 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3009 | } else { |
| 3010 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3011 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3012 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3013 | break; |
| 3014 | |
| 3015 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3016 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3017 | if (in.IsRegister()) { |
| 3018 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3019 | } else if (in.IsConstant()) { |
| 3020 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3021 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3022 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3023 | } else { |
| 3024 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3025 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3026 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3027 | break; |
| 3028 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3029 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3030 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3031 | if (in.IsFpuRegister()) { |
| 3032 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3033 | } else if (in.IsConstant()) { |
| 3034 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3035 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3036 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3037 | } else { |
| 3038 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3039 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3040 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3041 | break; |
| 3042 | |
| 3043 | default: |
| 3044 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3045 | << " to " << result_type; |
| 3046 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3047 | break; |
| 3048 | |
| 3049 | default: |
| 3050 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3051 | << " to " << result_type; |
| 3052 | } |
| 3053 | } |
| 3054 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3055 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3056 | LocationSummary* locations = |
| 3057 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3058 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3059 | case Primitive::kPrimInt: { |
| 3060 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3061 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3062 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3063 | break; |
| 3064 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3065 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3066 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3067 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3068 | // 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] | 3069 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3070 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3071 | break; |
| 3072 | } |
| 3073 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3074 | case Primitive::kPrimDouble: |
| 3075 | case Primitive::kPrimFloat: { |
| 3076 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3077 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3078 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3079 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3080 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3081 | |
| 3082 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3083 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3084 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3088 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3089 | Location first = locations->InAt(0); |
| 3090 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3091 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3092 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3093 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3094 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3095 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3096 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3097 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3098 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3099 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3100 | } else { |
| 3101 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3102 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3103 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3104 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3105 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3106 | __ addl(out.AsRegister<CpuRegister>(), |
| 3107 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3108 | } else { |
| 3109 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3110 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3111 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3112 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3113 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3114 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3115 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3116 | break; |
| 3117 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3118 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3119 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3120 | if (second.IsRegister()) { |
| 3121 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3122 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3123 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3124 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3125 | } else { |
| 3126 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3127 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3128 | } |
| 3129 | } else { |
| 3130 | DCHECK(second.IsConstant()); |
| 3131 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3132 | int32_t int32_value = Low32Bits(value); |
| 3133 | DCHECK_EQ(int32_value, value); |
| 3134 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3135 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3136 | } else { |
| 3137 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3138 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3139 | } |
| 3140 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3141 | break; |
| 3142 | } |
| 3143 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3144 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3145 | if (second.IsFpuRegister()) { |
| 3146 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3147 | } else if (second.IsConstant()) { |
| 3148 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3149 | codegen_->LiteralFloatAddress( |
| 3150 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3151 | } else { |
| 3152 | DCHECK(second.IsStackSlot()); |
| 3153 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3154 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3155 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3156 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3160 | if (second.IsFpuRegister()) { |
| 3161 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3162 | } else if (second.IsConstant()) { |
| 3163 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3164 | codegen_->LiteralDoubleAddress( |
| 3165 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3166 | } else { |
| 3167 | DCHECK(second.IsDoubleStackSlot()); |
| 3168 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3169 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3170 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3171 | break; |
| 3172 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3173 | |
| 3174 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3175 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3180 | LocationSummary* locations = |
| 3181 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3182 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3183 | case Primitive::kPrimInt: { |
| 3184 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3185 | locations->SetInAt(1, Location::Any()); |
| 3186 | locations->SetOut(Location::SameAsFirstInput()); |
| 3187 | break; |
| 3188 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3189 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3190 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3191 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3192 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3193 | break; |
| 3194 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3195 | case Primitive::kPrimFloat: |
| 3196 | case Primitive::kPrimDouble: { |
| 3197 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3198 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3199 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3200 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3201 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3202 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3203 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3204 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3205 | } |
| 3206 | |
| 3207 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3208 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3209 | Location first = locations->InAt(0); |
| 3210 | Location second = locations->InAt(1); |
| 3211 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3212 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3213 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3214 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3215 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3216 | } else if (second.IsConstant()) { |
| 3217 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3218 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3219 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3220 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3221 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3222 | break; |
| 3223 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3224 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3225 | if (second.IsConstant()) { |
| 3226 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3227 | DCHECK(IsInt<32>(value)); |
| 3228 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3229 | } else { |
| 3230 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3231 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3232 | break; |
| 3233 | } |
| 3234 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3235 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3236 | if (second.IsFpuRegister()) { |
| 3237 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3238 | } else if (second.IsConstant()) { |
| 3239 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3240 | codegen_->LiteralFloatAddress( |
| 3241 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3242 | } else { |
| 3243 | DCHECK(second.IsStackSlot()); |
| 3244 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3245 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3246 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3247 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3251 | if (second.IsFpuRegister()) { |
| 3252 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3253 | } else if (second.IsConstant()) { |
| 3254 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3255 | codegen_->LiteralDoubleAddress( |
| 3256 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3257 | } else { |
| 3258 | DCHECK(second.IsDoubleStackSlot()); |
| 3259 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3260 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3261 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3262 | break; |
| 3263 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3264 | |
| 3265 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3266 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3267 | } |
| 3268 | } |
| 3269 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3270 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3271 | LocationSummary* locations = |
| 3272 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3273 | switch (mul->GetResultType()) { |
| 3274 | case Primitive::kPrimInt: { |
| 3275 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3276 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3277 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3278 | // Can use 3 operand multiply. |
| 3279 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3280 | } else { |
| 3281 | locations->SetOut(Location::SameAsFirstInput()); |
| 3282 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3283 | break; |
| 3284 | } |
| 3285 | case Primitive::kPrimLong: { |
| 3286 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3287 | locations->SetInAt(1, Location::Any()); |
| 3288 | if (mul->InputAt(1)->IsLongConstant() && |
| 3289 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3290 | // Can use 3 operand multiply. |
| 3291 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3292 | } else { |
| 3293 | locations->SetOut(Location::SameAsFirstInput()); |
| 3294 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3295 | break; |
| 3296 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3297 | case Primitive::kPrimFloat: |
| 3298 | case Primitive::kPrimDouble: { |
| 3299 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3300 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3301 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3302 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3303 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3304 | |
| 3305 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3306 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3307 | } |
| 3308 | } |
| 3309 | |
| 3310 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3311 | LocationSummary* locations = mul->GetLocations(); |
| 3312 | Location first = locations->InAt(0); |
| 3313 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3314 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3315 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3316 | case Primitive::kPrimInt: |
| 3317 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3318 | // problems where the output may not be the same as the first operand. |
| 3319 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3320 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3321 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3322 | } else if (second.IsRegister()) { |
| 3323 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3324 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3325 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3326 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3327 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3328 | __ imull(first.AsRegister<CpuRegister>(), |
| 3329 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3330 | } |
| 3331 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3332 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3333 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3334 | // problems where the output may not be the same as the first operand. |
| 3335 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3336 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3337 | if (IsInt<32>(value)) { |
| 3338 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3339 | Immediate(static_cast<int32_t>(value))); |
| 3340 | } else { |
| 3341 | // Have to use the constant area. |
| 3342 | DCHECK(first.Equals(out)); |
| 3343 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3344 | } |
| 3345 | } else if (second.IsRegister()) { |
| 3346 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3347 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3348 | } else { |
| 3349 | DCHECK(second.IsDoubleStackSlot()); |
| 3350 | DCHECK(first.Equals(out)); |
| 3351 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3352 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3353 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3354 | break; |
| 3355 | } |
| 3356 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3357 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3358 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3359 | if (second.IsFpuRegister()) { |
| 3360 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3361 | } else if (second.IsConstant()) { |
| 3362 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3363 | codegen_->LiteralFloatAddress( |
| 3364 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3365 | } else { |
| 3366 | DCHECK(second.IsStackSlot()); |
| 3367 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3368 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3369 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3370 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3374 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3375 | if (second.IsFpuRegister()) { |
| 3376 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3377 | } else if (second.IsConstant()) { |
| 3378 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3379 | codegen_->LiteralDoubleAddress( |
| 3380 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3381 | } else { |
| 3382 | DCHECK(second.IsDoubleStackSlot()); |
| 3383 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3384 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3385 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3386 | break; |
| 3387 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3388 | |
| 3389 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3390 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3391 | } |
| 3392 | } |
| 3393 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3394 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3395 | uint32_t stack_adjustment, bool is_float) { |
| 3396 | if (source.IsStackSlot()) { |
| 3397 | DCHECK(is_float); |
| 3398 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3399 | } else if (source.IsDoubleStackSlot()) { |
| 3400 | DCHECK(!is_float); |
| 3401 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3402 | } else { |
| 3403 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3404 | if (is_float) { |
| 3405 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3406 | codegen_->Move(stack_temp, source); |
| 3407 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3408 | } else { |
| 3409 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3410 | codegen_->Move(stack_temp, source); |
| 3411 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3412 | } |
| 3413 | } |
| 3414 | } |
| 3415 | |
| 3416 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3417 | Primitive::Type type = rem->GetResultType(); |
| 3418 | bool is_float = type == Primitive::kPrimFloat; |
| 3419 | size_t elem_size = Primitive::ComponentSize(type); |
| 3420 | LocationSummary* locations = rem->GetLocations(); |
| 3421 | Location first = locations->InAt(0); |
| 3422 | Location second = locations->InAt(1); |
| 3423 | Location out = locations->Out(); |
| 3424 | |
| 3425 | // Create stack space for 2 elements. |
| 3426 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3427 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3428 | |
| 3429 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3430 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3431 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3432 | |
| 3433 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3434 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3435 | __ Bind(&retry); |
| 3436 | __ fprem(); |
| 3437 | |
| 3438 | // Move FP status to AX. |
| 3439 | __ fstsw(); |
| 3440 | |
| 3441 | // And see if the argument reduction is complete. This is signaled by the |
| 3442 | // C2 FPU flag bit set to 0. |
| 3443 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3444 | __ j(kNotEqual, &retry); |
| 3445 | |
| 3446 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3447 | // Store FP top of stack to real stack. |
| 3448 | if (is_float) { |
| 3449 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3450 | } else { |
| 3451 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3452 | } |
| 3453 | |
| 3454 | // Pop the 2 items from the FP stack. |
| 3455 | __ fucompp(); |
| 3456 | |
| 3457 | // Load the value from the stack into an XMM register. |
| 3458 | DCHECK(out.IsFpuRegister()) << out; |
| 3459 | if (is_float) { |
| 3460 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3461 | } else { |
| 3462 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3463 | } |
| 3464 | |
| 3465 | // And remove the temporary stack space we allocated. |
| 3466 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3467 | } |
| 3468 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3469 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3470 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3471 | |
| 3472 | LocationSummary* locations = instruction->GetLocations(); |
| 3473 | Location second = locations->InAt(1); |
| 3474 | DCHECK(second.IsConstant()); |
| 3475 | |
| 3476 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3477 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3478 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3479 | |
| 3480 | DCHECK(imm == 1 || imm == -1); |
| 3481 | |
| 3482 | switch (instruction->GetResultType()) { |
| 3483 | case Primitive::kPrimInt: { |
| 3484 | if (instruction->IsRem()) { |
| 3485 | __ xorl(output_register, output_register); |
| 3486 | } else { |
| 3487 | __ movl(output_register, input_register); |
| 3488 | if (imm == -1) { |
| 3489 | __ negl(output_register); |
| 3490 | } |
| 3491 | } |
| 3492 | break; |
| 3493 | } |
| 3494 | |
| 3495 | case Primitive::kPrimLong: { |
| 3496 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3497 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3498 | } else { |
| 3499 | __ movq(output_register, input_register); |
| 3500 | if (imm == -1) { |
| 3501 | __ negq(output_register); |
| 3502 | } |
| 3503 | } |
| 3504 | break; |
| 3505 | } |
| 3506 | |
| 3507 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3508 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3509 | } |
| 3510 | } |
| 3511 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3512 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3513 | LocationSummary* locations = instruction->GetLocations(); |
| 3514 | Location second = locations->InAt(1); |
| 3515 | |
| 3516 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3517 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3518 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3519 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3520 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3521 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3522 | |
| 3523 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3524 | |
| 3525 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3526 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3527 | __ testl(numerator, numerator); |
| 3528 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3529 | int shift = CTZ(imm); |
| 3530 | __ sarl(tmp, Immediate(shift)); |
| 3531 | |
| 3532 | if (imm < 0) { |
| 3533 | __ negl(tmp); |
| 3534 | } |
| 3535 | |
| 3536 | __ movl(output_register, tmp); |
| 3537 | } else { |
| 3538 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3539 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3540 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3541 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3542 | __ addq(rdx, numerator); |
| 3543 | __ testq(numerator, numerator); |
| 3544 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3545 | int shift = CTZ(imm); |
| 3546 | __ sarq(rdx, Immediate(shift)); |
| 3547 | |
| 3548 | if (imm < 0) { |
| 3549 | __ negq(rdx); |
| 3550 | } |
| 3551 | |
| 3552 | __ movq(output_register, rdx); |
| 3553 | } |
| 3554 | } |
| 3555 | |
| 3556 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3557 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3558 | |
| 3559 | LocationSummary* locations = instruction->GetLocations(); |
| 3560 | Location second = locations->InAt(1); |
| 3561 | |
| 3562 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3563 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3564 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3565 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3566 | : locations->Out().AsRegister<CpuRegister>(); |
| 3567 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3568 | |
| 3569 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3570 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3571 | if (instruction->IsDiv()) { |
| 3572 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3573 | } else { |
| 3574 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3575 | } |
| 3576 | |
| 3577 | int64_t magic; |
| 3578 | int shift; |
| 3579 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3580 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3581 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3582 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3583 | |
| 3584 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3585 | |
| 3586 | __ movl(numerator, eax); |
| 3587 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3588 | __ movl(eax, Immediate(magic)); |
| 3589 | __ imull(numerator); |
| 3590 | |
| 3591 | if (imm > 0 && magic < 0) { |
| 3592 | __ addl(edx, numerator); |
| 3593 | } else if (imm < 0 && magic > 0) { |
| 3594 | __ subl(edx, numerator); |
| 3595 | } |
| 3596 | |
| 3597 | if (shift != 0) { |
| 3598 | __ sarl(edx, Immediate(shift)); |
| 3599 | } |
| 3600 | |
| 3601 | __ movl(eax, edx); |
| 3602 | __ shrl(edx, Immediate(31)); |
| 3603 | __ addl(edx, eax); |
| 3604 | |
| 3605 | if (instruction->IsRem()) { |
| 3606 | __ movl(eax, numerator); |
| 3607 | __ imull(edx, Immediate(imm)); |
| 3608 | __ subl(eax, edx); |
| 3609 | __ movl(edx, eax); |
| 3610 | } else { |
| 3611 | __ movl(eax, edx); |
| 3612 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3613 | } else { |
| 3614 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3615 | |
| 3616 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3617 | |
| 3618 | CpuRegister rax = eax; |
| 3619 | CpuRegister rdx = edx; |
| 3620 | |
| 3621 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3622 | |
| 3623 | // Save the numerator. |
| 3624 | __ movq(numerator, rax); |
| 3625 | |
| 3626 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3627 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3628 | |
| 3629 | // RDX:RAX = magic * numerator |
| 3630 | __ imulq(numerator); |
| 3631 | |
| 3632 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3633 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3634 | __ addq(rdx, numerator); |
| 3635 | } else if (imm < 0 && magic > 0) { |
| 3636 | // RDX -= numerator |
| 3637 | __ subq(rdx, numerator); |
| 3638 | } |
| 3639 | |
| 3640 | // Shift if needed. |
| 3641 | if (shift != 0) { |
| 3642 | __ sarq(rdx, Immediate(shift)); |
| 3643 | } |
| 3644 | |
| 3645 | // RDX += 1 if RDX < 0 |
| 3646 | __ movq(rax, rdx); |
| 3647 | __ shrq(rdx, Immediate(63)); |
| 3648 | __ addq(rdx, rax); |
| 3649 | |
| 3650 | if (instruction->IsRem()) { |
| 3651 | __ movq(rax, numerator); |
| 3652 | |
| 3653 | if (IsInt<32>(imm)) { |
| 3654 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3655 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3656 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | __ subq(rax, rdx); |
| 3660 | __ movq(rdx, rax); |
| 3661 | } else { |
| 3662 | __ movq(rax, rdx); |
| 3663 | } |
| 3664 | } |
| 3665 | } |
| 3666 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3667 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3668 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3669 | Primitive::Type type = instruction->GetResultType(); |
| 3670 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3671 | |
| 3672 | bool is_div = instruction->IsDiv(); |
| 3673 | LocationSummary* locations = instruction->GetLocations(); |
| 3674 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3675 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3676 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3677 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3678 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3679 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3680 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3681 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3682 | int64_t imm = Int64FromConstant(second.GetConstant()); |
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 (imm == 0) { |
| 3685 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3686 | } else if (imm == 1 || imm == -1) { |
| 3687 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3688 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3689 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3690 | } else { |
| 3691 | DCHECK(imm <= -2 || imm >= 2); |
| 3692 | GenerateDivRemWithAnyConstant(instruction); |
| 3693 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3694 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3695 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3696 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3697 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3698 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3699 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3700 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3701 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3702 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3703 | // so it's safe to just use negl instead of more complex comparisons. |
| 3704 | if (type == Primitive::kPrimInt) { |
| 3705 | __ cmpl(second_reg, Immediate(-1)); |
| 3706 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3707 | // edx:eax <- sign-extended of eax |
| 3708 | __ cdq(); |
| 3709 | // eax = quotient, edx = remainder |
| 3710 | __ idivl(second_reg); |
| 3711 | } else { |
| 3712 | __ cmpq(second_reg, Immediate(-1)); |
| 3713 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3714 | // rdx:rax <- sign-extended of rax |
| 3715 | __ cqo(); |
| 3716 | // rax = quotient, rdx = remainder |
| 3717 | __ idivq(second_reg); |
| 3718 | } |
| 3719 | __ Bind(slow_path->GetExitLabel()); |
| 3720 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3721 | } |
| 3722 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3723 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3724 | LocationSummary* locations = |
| 3725 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3726 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3727 | case Primitive::kPrimInt: |
| 3728 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3729 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3730 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3731 | locations->SetOut(Location::SameAsFirstInput()); |
| 3732 | // Intel uses edx:eax as the dividend. |
| 3733 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3734 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3735 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3736 | // output and request another temp. |
| 3737 | if (div->InputAt(1)->IsConstant()) { |
| 3738 | locations->AddTemp(Location::RequiresRegister()); |
| 3739 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3740 | break; |
| 3741 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3742 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3743 | case Primitive::kPrimFloat: |
| 3744 | case Primitive::kPrimDouble: { |
| 3745 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3746 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3747 | locations->SetOut(Location::SameAsFirstInput()); |
| 3748 | break; |
| 3749 | } |
| 3750 | |
| 3751 | default: |
| 3752 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3753 | } |
| 3754 | } |
| 3755 | |
| 3756 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3757 | LocationSummary* locations = div->GetLocations(); |
| 3758 | Location first = locations->InAt(0); |
| 3759 | Location second = locations->InAt(1); |
| 3760 | DCHECK(first.Equals(locations->Out())); |
| 3761 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3762 | Primitive::Type type = div->GetResultType(); |
| 3763 | switch (type) { |
| 3764 | case Primitive::kPrimInt: |
| 3765 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3766 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3767 | break; |
| 3768 | } |
| 3769 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3770 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3771 | if (second.IsFpuRegister()) { |
| 3772 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3773 | } else if (second.IsConstant()) { |
| 3774 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3775 | codegen_->LiteralFloatAddress( |
| 3776 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3777 | } else { |
| 3778 | DCHECK(second.IsStackSlot()); |
| 3779 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3780 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3781 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3782 | break; |
| 3783 | } |
| 3784 | |
| 3785 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3786 | if (second.IsFpuRegister()) { |
| 3787 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3788 | } else if (second.IsConstant()) { |
| 3789 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3790 | codegen_->LiteralDoubleAddress( |
| 3791 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3792 | } else { |
| 3793 | DCHECK(second.IsDoubleStackSlot()); |
| 3794 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3795 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3796 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3797 | break; |
| 3798 | } |
| 3799 | |
| 3800 | default: |
| 3801 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3802 | } |
| 3803 | } |
| 3804 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3805 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3806 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3807 | LocationSummary* locations = |
| 3808 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3809 | |
| 3810 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3811 | case Primitive::kPrimInt: |
| 3812 | case Primitive::kPrimLong: { |
| 3813 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3814 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3815 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3816 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3817 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3818 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3819 | // output and request another temp. |
| 3820 | if (rem->InputAt(1)->IsConstant()) { |
| 3821 | locations->AddTemp(Location::RequiresRegister()); |
| 3822 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3823 | break; |
| 3824 | } |
| 3825 | |
| 3826 | case Primitive::kPrimFloat: |
| 3827 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3828 | locations->SetInAt(0, Location::Any()); |
| 3829 | locations->SetInAt(1, Location::Any()); |
| 3830 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3831 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3832 | break; |
| 3833 | } |
| 3834 | |
| 3835 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3836 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3837 | } |
| 3838 | } |
| 3839 | |
| 3840 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3841 | Primitive::Type type = rem->GetResultType(); |
| 3842 | switch (type) { |
| 3843 | case Primitive::kPrimInt: |
| 3844 | case Primitive::kPrimLong: { |
| 3845 | GenerateDivRemIntegral(rem); |
| 3846 | break; |
| 3847 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3848 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3849 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3850 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3851 | break; |
| 3852 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3853 | default: |
| 3854 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3855 | } |
| 3856 | } |
| 3857 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3858 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3859 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3860 | locations->SetInAt(0, Location::Any()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3864 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3865 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3866 | codegen_->AddSlowPath(slow_path); |
| 3867 | |
| 3868 | LocationSummary* locations = instruction->GetLocations(); |
| 3869 | Location value = locations->InAt(0); |
| 3870 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3871 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3872 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3873 | case Primitive::kPrimByte: |
| 3874 | case Primitive::kPrimChar: |
| 3875 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3876 | case Primitive::kPrimInt: { |
| 3877 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3878 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3879 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3880 | } else if (value.IsStackSlot()) { |
| 3881 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3882 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3883 | } else { |
| 3884 | DCHECK(value.IsConstant()) << value; |
| 3885 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3886 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3887 | } |
| 3888 | } |
| 3889 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3890 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3891 | case Primitive::kPrimLong: { |
| 3892 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3893 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3894 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3895 | } else if (value.IsDoubleStackSlot()) { |
| 3896 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3897 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3898 | } else { |
| 3899 | DCHECK(value.IsConstant()) << value; |
| 3900 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3901 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3902 | } |
| 3903 | } |
| 3904 | break; |
| 3905 | } |
| 3906 | default: |
| 3907 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3908 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3909 | } |
| 3910 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3911 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3912 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3913 | |
| 3914 | LocationSummary* locations = |
| 3915 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3916 | |
| 3917 | switch (op->GetResultType()) { |
| 3918 | case Primitive::kPrimInt: |
| 3919 | case Primitive::kPrimLong: { |
| 3920 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3921 | // The shift count needs to be in CL. |
| 3922 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3923 | locations->SetOut(Location::SameAsFirstInput()); |
| 3924 | break; |
| 3925 | } |
| 3926 | default: |
| 3927 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3928 | } |
| 3929 | } |
| 3930 | |
| 3931 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3932 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3933 | |
| 3934 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3935 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3936 | Location second = locations->InAt(1); |
| 3937 | |
| 3938 | switch (op->GetResultType()) { |
| 3939 | case Primitive::kPrimInt: { |
| 3940 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3941 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3942 | if (op->IsShl()) { |
| 3943 | __ shll(first_reg, second_reg); |
| 3944 | } else if (op->IsShr()) { |
| 3945 | __ sarl(first_reg, second_reg); |
| 3946 | } else { |
| 3947 | __ shrl(first_reg, second_reg); |
| 3948 | } |
| 3949 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3950 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3951 | if (op->IsShl()) { |
| 3952 | __ shll(first_reg, imm); |
| 3953 | } else if (op->IsShr()) { |
| 3954 | __ sarl(first_reg, imm); |
| 3955 | } else { |
| 3956 | __ shrl(first_reg, imm); |
| 3957 | } |
| 3958 | } |
| 3959 | break; |
| 3960 | } |
| 3961 | case Primitive::kPrimLong: { |
| 3962 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3963 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3964 | if (op->IsShl()) { |
| 3965 | __ shlq(first_reg, second_reg); |
| 3966 | } else if (op->IsShr()) { |
| 3967 | __ sarq(first_reg, second_reg); |
| 3968 | } else { |
| 3969 | __ shrq(first_reg, second_reg); |
| 3970 | } |
| 3971 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3972 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3973 | if (op->IsShl()) { |
| 3974 | __ shlq(first_reg, imm); |
| 3975 | } else if (op->IsShr()) { |
| 3976 | __ sarq(first_reg, imm); |
| 3977 | } else { |
| 3978 | __ shrq(first_reg, imm); |
| 3979 | } |
| 3980 | } |
| 3981 | break; |
| 3982 | } |
| 3983 | default: |
| 3984 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3985 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3986 | } |
| 3987 | } |
| 3988 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3989 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3990 | LocationSummary* locations = |
| 3991 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3992 | |
| 3993 | switch (ror->GetResultType()) { |
| 3994 | case Primitive::kPrimInt: |
| 3995 | case Primitive::kPrimLong: { |
| 3996 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3997 | // The shift count needs to be in CL (unless it is a constant). |
| 3998 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3999 | locations->SetOut(Location::SameAsFirstInput()); |
| 4000 | break; |
| 4001 | } |
| 4002 | default: |
| 4003 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4004 | UNREACHABLE(); |
| 4005 | } |
| 4006 | } |
| 4007 | |
| 4008 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4009 | LocationSummary* locations = ror->GetLocations(); |
| 4010 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4011 | Location second = locations->InAt(1); |
| 4012 | |
| 4013 | switch (ror->GetResultType()) { |
| 4014 | case Primitive::kPrimInt: |
| 4015 | if (second.IsRegister()) { |
| 4016 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4017 | __ rorl(first_reg, second_reg); |
| 4018 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4019 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4020 | __ rorl(first_reg, imm); |
| 4021 | } |
| 4022 | break; |
| 4023 | case Primitive::kPrimLong: |
| 4024 | if (second.IsRegister()) { |
| 4025 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4026 | __ rorq(first_reg, second_reg); |
| 4027 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4028 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4029 | __ rorq(first_reg, imm); |
| 4030 | } |
| 4031 | break; |
| 4032 | default: |
| 4033 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4034 | UNREACHABLE(); |
| 4035 | } |
| 4036 | } |
| 4037 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4038 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4039 | HandleShift(shl); |
| 4040 | } |
| 4041 | |
| 4042 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4043 | HandleShift(shl); |
| 4044 | } |
| 4045 | |
| 4046 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4047 | HandleShift(shr); |
| 4048 | } |
| 4049 | |
| 4050 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4051 | HandleShift(shr); |
| 4052 | } |
| 4053 | |
| 4054 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4055 | HandleShift(ushr); |
| 4056 | } |
| 4057 | |
| 4058 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4059 | HandleShift(ushr); |
| 4060 | } |
| 4061 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4062 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4063 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4064 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4065 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4066 | if (instruction->IsStringAlloc()) { |
| 4067 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4068 | } else { |
| 4069 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4070 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4071 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4072 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4073 | } |
| 4074 | |
| 4075 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4076 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4077 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4078 | if (instruction->IsStringAlloc()) { |
| 4079 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4080 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4081 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4082 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 4083 | __ call(Address(temp, code_offset.SizeValue())); |
| 4084 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4085 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4086 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4087 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4088 | DCHECK(!codegen_->IsLeafMethod()); |
| 4089 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4090 | } |
| 4091 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4092 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 4093 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 4094 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4095 | InvokeRuntimeCallingConvention calling_convention; |
| 4096 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4097 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4098 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4099 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 4103 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4104 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 4105 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4106 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4107 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4108 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4109 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4110 | |
| 4111 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4112 | } |
| 4113 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4114 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4115 | LocationSummary* locations = |
| 4116 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4117 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4118 | if (location.IsStackSlot()) { |
| 4119 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4120 | } else if (location.IsDoubleStackSlot()) { |
| 4121 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4122 | } |
| 4123 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4124 | } |
| 4125 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4126 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4127 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4128 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4132 | LocationSummary* locations = |
| 4133 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4134 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4135 | } |
| 4136 | |
| 4137 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4138 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4139 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4140 | } |
| 4141 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4142 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4143 | LocationSummary* locations = |
| 4144 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4145 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4146 | locations->SetOut(Location::RequiresRegister()); |
| 4147 | } |
| 4148 | |
| 4149 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4150 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4151 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4152 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4153 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4154 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4155 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4156 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4157 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4158 | instruction->GetIndex(), kX86_64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4159 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4160 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4161 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4162 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4163 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4164 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4165 | } |
| 4166 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4167 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4168 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4169 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4170 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4171 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4172 | } |
| 4173 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4174 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4175 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4176 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4177 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4178 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4179 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4180 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4181 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4182 | break; |
| 4183 | |
| 4184 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4185 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4186 | break; |
| 4187 | |
| 4188 | default: |
| 4189 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4190 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4191 | } |
| 4192 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4193 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4194 | LocationSummary* locations = |
| 4195 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4196 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4197 | locations->SetOut(Location::SameAsFirstInput()); |
| 4198 | } |
| 4199 | |
| 4200 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4201 | LocationSummary* locations = bool_not->GetLocations(); |
| 4202 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4203 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4204 | Location out = locations->Out(); |
| 4205 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4206 | } |
| 4207 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4208 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4209 | LocationSummary* locations = |
| 4210 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4211 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4212 | locations->SetInAt(i, Location::Any()); |
| 4213 | } |
| 4214 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4215 | } |
| 4216 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4217 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4218 | LOG(FATAL) << "Unimplemented"; |
| 4219 | } |
| 4220 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4221 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4222 | /* |
| 4223 | * 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] | 4224 | * 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] | 4225 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4226 | */ |
| 4227 | switch (kind) { |
| 4228 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4229 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4230 | break; |
| 4231 | } |
| 4232 | case MemBarrierKind::kAnyStore: |
| 4233 | case MemBarrierKind::kLoadAny: |
| 4234 | case MemBarrierKind::kStoreStore: { |
| 4235 | // nop |
| 4236 | break; |
| 4237 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4238 | case MemBarrierKind::kNTStoreStore: |
| 4239 | // Non-Temporal Store/Store needs an explicit fence. |
| 4240 | MemoryFence(/* non-temporal */ true); |
| 4241 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4242 | } |
| 4243 | } |
| 4244 | |
| 4245 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4246 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4247 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4248 | bool object_field_get_with_read_barrier = |
| 4249 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4250 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4251 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4252 | object_field_get_with_read_barrier ? |
| 4253 | LocationSummary::kCallOnSlowPath : |
| 4254 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4255 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4256 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4257 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4258 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4259 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4260 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4261 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4262 | // The output overlaps for an object field get when read barriers |
| 4263 | // are enabled: we do not want the move to overwrite the object's |
| 4264 | // location, as we need it to emit the read barrier. |
| 4265 | locations->SetOut( |
| 4266 | Location::RequiresRegister(), |
| 4267 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4268 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4272 | const FieldInfo& field_info) { |
| 4273 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4274 | |
| 4275 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4276 | Location base_loc = locations->InAt(0); |
| 4277 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4278 | Location out = locations->Out(); |
| 4279 | bool is_volatile = field_info.IsVolatile(); |
| 4280 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4281 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4282 | |
| 4283 | switch (field_type) { |
| 4284 | case Primitive::kPrimBoolean: { |
| 4285 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4286 | break; |
| 4287 | } |
| 4288 | |
| 4289 | case Primitive::kPrimByte: { |
| 4290 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4291 | break; |
| 4292 | } |
| 4293 | |
| 4294 | case Primitive::kPrimShort: { |
| 4295 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4296 | break; |
| 4297 | } |
| 4298 | |
| 4299 | case Primitive::kPrimChar: { |
| 4300 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4301 | break; |
| 4302 | } |
| 4303 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4304 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4305 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4306 | break; |
| 4307 | } |
| 4308 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4309 | case Primitive::kPrimNot: { |
| 4310 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4311 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4312 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4313 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4314 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4315 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4316 | if (is_volatile) { |
| 4317 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4318 | } |
| 4319 | } else { |
| 4320 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4321 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4322 | if (is_volatile) { |
| 4323 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4324 | } |
| 4325 | // If read barriers are enabled, emit read barriers other than |
| 4326 | // Baker's using a slow path (and also unpoison the loaded |
| 4327 | // reference, if heap poisoning is enabled). |
| 4328 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4329 | } |
| 4330 | break; |
| 4331 | } |
| 4332 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4333 | case Primitive::kPrimLong: { |
| 4334 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4335 | break; |
| 4336 | } |
| 4337 | |
| 4338 | case Primitive::kPrimFloat: { |
| 4339 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4340 | break; |
| 4341 | } |
| 4342 | |
| 4343 | case Primitive::kPrimDouble: { |
| 4344 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4345 | break; |
| 4346 | } |
| 4347 | |
| 4348 | case Primitive::kPrimVoid: |
| 4349 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4350 | UNREACHABLE(); |
| 4351 | } |
| 4352 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4353 | if (field_type == Primitive::kPrimNot) { |
| 4354 | // Potential implicit null checks, in the case of reference |
| 4355 | // fields, are handled in the previous switch statement. |
| 4356 | } else { |
| 4357 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4358 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4359 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4360 | if (is_volatile) { |
| 4361 | if (field_type == Primitive::kPrimNot) { |
| 4362 | // Memory barriers, in the case of references, are also handled |
| 4363 | // in the previous switch statement. |
| 4364 | } else { |
| 4365 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4366 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4367 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4371 | const FieldInfo& field_info) { |
| 4372 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4373 | |
| 4374 | LocationSummary* locations = |
| 4375 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4376 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4377 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4378 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4379 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4380 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4381 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4382 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4383 | if (is_volatile) { |
| 4384 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4385 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4386 | } else { |
| 4387 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4388 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4389 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4390 | if (is_volatile) { |
| 4391 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4392 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4393 | } else { |
| 4394 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4395 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4396 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4397 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4398 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4399 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4400 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4401 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4402 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4403 | locations->AddTemp(Location::RequiresRegister()); |
| 4404 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4405 | } |
| 4406 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4407 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4408 | const FieldInfo& field_info, |
| 4409 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4410 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4411 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4412 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4413 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4414 | Location value = locations->InAt(1); |
| 4415 | bool is_volatile = field_info.IsVolatile(); |
| 4416 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4417 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4418 | |
| 4419 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4420 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4421 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4422 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4423 | bool maybe_record_implicit_null_check_done = false; |
| 4424 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4425 | switch (field_type) { |
| 4426 | case Primitive::kPrimBoolean: |
| 4427 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4428 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4429 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4430 | __ movb(Address(base, offset), Immediate(v)); |
| 4431 | } else { |
| 4432 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4433 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4434 | break; |
| 4435 | } |
| 4436 | |
| 4437 | case Primitive::kPrimShort: |
| 4438 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4439 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4440 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4441 | __ movw(Address(base, offset), Immediate(v)); |
| 4442 | } else { |
| 4443 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4444 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4445 | break; |
| 4446 | } |
| 4447 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4448 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4449 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4450 | if (value.IsConstant()) { |
| 4451 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4452 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4453 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4454 | // Note: if heap poisoning is enabled, no need to poison |
| 4455 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4456 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4457 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4458 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4459 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4460 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4461 | __ PoisonHeapReference(temp); |
| 4462 | __ movl(Address(base, offset), temp); |
| 4463 | } else { |
| 4464 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4465 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4466 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4467 | break; |
| 4468 | } |
| 4469 | |
| 4470 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4471 | if (value.IsConstant()) { |
| 4472 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4473 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4474 | Address(base, offset + sizeof(int32_t)), |
| 4475 | v, |
| 4476 | instruction); |
| 4477 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4478 | } else { |
| 4479 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4480 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4481 | break; |
| 4482 | } |
| 4483 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4484 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4485 | if (value.IsConstant()) { |
| 4486 | int32_t v = |
| 4487 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4488 | __ movl(Address(base, offset), Immediate(v)); |
| 4489 | } else { |
| 4490 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4491 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4492 | break; |
| 4493 | } |
| 4494 | |
| 4495 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4496 | if (value.IsConstant()) { |
| 4497 | int64_t v = |
| 4498 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4499 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4500 | Address(base, offset + sizeof(int32_t)), |
| 4501 | v, |
| 4502 | instruction); |
| 4503 | maybe_record_implicit_null_check_done = true; |
| 4504 | } else { |
| 4505 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4506 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4507 | break; |
| 4508 | } |
| 4509 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4510 | case Primitive::kPrimVoid: |
| 4511 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4512 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4513 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4514 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4515 | if (!maybe_record_implicit_null_check_done) { |
| 4516 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4517 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4518 | |
| 4519 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4520 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4521 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4522 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4523 | } |
| 4524 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4525 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4526 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4527 | } |
| 4528 | } |
| 4529 | |
| 4530 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4531 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4532 | } |
| 4533 | |
| 4534 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4535 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4536 | } |
| 4537 | |
| 4538 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4539 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4540 | } |
| 4541 | |
| 4542 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4543 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4544 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4545 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4546 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4547 | HandleFieldGet(instruction); |
| 4548 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4549 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4550 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4551 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4552 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4553 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4554 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4555 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4556 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4557 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4558 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4559 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4560 | } |
| 4561 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4562 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4563 | HUnresolvedInstanceFieldGet* instruction) { |
| 4564 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4565 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4566 | instruction, instruction->GetFieldType(), calling_convention); |
| 4567 | } |
| 4568 | |
| 4569 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4570 | HUnresolvedInstanceFieldGet* instruction) { |
| 4571 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4572 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4573 | instruction->GetFieldType(), |
| 4574 | instruction->GetFieldIndex(), |
| 4575 | instruction->GetDexPc(), |
| 4576 | calling_convention); |
| 4577 | } |
| 4578 | |
| 4579 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4580 | HUnresolvedInstanceFieldSet* instruction) { |
| 4581 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4582 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4583 | instruction, instruction->GetFieldType(), calling_convention); |
| 4584 | } |
| 4585 | |
| 4586 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4587 | HUnresolvedInstanceFieldSet* instruction) { |
| 4588 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4589 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4590 | instruction->GetFieldType(), |
| 4591 | instruction->GetFieldIndex(), |
| 4592 | instruction->GetDexPc(), |
| 4593 | calling_convention); |
| 4594 | } |
| 4595 | |
| 4596 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4597 | HUnresolvedStaticFieldGet* instruction) { |
| 4598 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4599 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4600 | instruction, instruction->GetFieldType(), calling_convention); |
| 4601 | } |
| 4602 | |
| 4603 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4604 | HUnresolvedStaticFieldGet* instruction) { |
| 4605 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4606 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4607 | instruction->GetFieldType(), |
| 4608 | instruction->GetFieldIndex(), |
| 4609 | instruction->GetDexPc(), |
| 4610 | calling_convention); |
| 4611 | } |
| 4612 | |
| 4613 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4614 | HUnresolvedStaticFieldSet* instruction) { |
| 4615 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4616 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4617 | instruction, instruction->GetFieldType(), calling_convention); |
| 4618 | } |
| 4619 | |
| 4620 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4621 | HUnresolvedStaticFieldSet* instruction) { |
| 4622 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4623 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4624 | instruction->GetFieldType(), |
| 4625 | instruction->GetFieldIndex(), |
| 4626 | instruction->GetDexPc(), |
| 4627 | calling_convention); |
| 4628 | } |
| 4629 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4630 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4631 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4632 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4633 | ? Location::RequiresRegister() |
| 4634 | : Location::Any(); |
| 4635 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4636 | } |
| 4637 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4638 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4639 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4640 | return; |
| 4641 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4642 | LocationSummary* locations = instruction->GetLocations(); |
| 4643 | Location obj = locations->InAt(0); |
| 4644 | |
| 4645 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4646 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4647 | } |
| 4648 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4649 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4650 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4651 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4652 | |
| 4653 | LocationSummary* locations = instruction->GetLocations(); |
| 4654 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4655 | |
| 4656 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4657 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4658 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4659 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4660 | } else { |
| 4661 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4662 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4663 | __ jmp(slow_path->GetEntryLabel()); |
| 4664 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4665 | } |
| 4666 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4667 | } |
| 4668 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4669 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4670 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4671 | } |
| 4672 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4673 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4674 | bool object_array_get_with_read_barrier = |
| 4675 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4676 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4677 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4678 | object_array_get_with_read_barrier ? |
| 4679 | LocationSummary::kCallOnSlowPath : |
| 4680 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4681 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4682 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4683 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4684 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4685 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4686 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4687 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4688 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4689 | // The output overlaps for an object array get when read barriers |
| 4690 | // are enabled: we do not want the move to overwrite the array's |
| 4691 | // location, as we need it to emit the read barrier. |
| 4692 | locations->SetOut( |
| 4693 | Location::RequiresRegister(), |
| 4694 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4695 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4699 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4700 | Location obj_loc = locations->InAt(0); |
| 4701 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4702 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4703 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4704 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4705 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4706 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4707 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4708 | case Primitive::kPrimBoolean: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4709 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4710 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4711 | break; |
| 4712 | } |
| 4713 | |
| 4714 | case Primitive::kPrimByte: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4715 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4716 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4717 | break; |
| 4718 | } |
| 4719 | |
| 4720 | case Primitive::kPrimShort: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4721 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4722 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4723 | break; |
| 4724 | } |
| 4725 | |
| 4726 | case Primitive::kPrimChar: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4727 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4728 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 4729 | // Branch cases into compressed and uncompressed for each index's type. |
| 4730 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4731 | NearLabel done, not_compressed; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame^] | 4732 | __ testl(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4733 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame^] | 4734 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4735 | "Expecting 0=compressed, 1=uncompressed"); |
| 4736 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4737 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 4738 | __ jmp(&done); |
| 4739 | __ Bind(¬_compressed); |
| 4740 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4741 | __ Bind(&done); |
| 4742 | } else { |
| 4743 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4744 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4745 | break; |
| 4746 | } |
| 4747 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4748 | case Primitive::kPrimInt: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4749 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4750 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4751 | break; |
| 4752 | } |
| 4753 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4754 | case Primitive::kPrimNot: { |
| 4755 | static_assert( |
| 4756 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4757 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4758 | // /* HeapReference<Object> */ out = |
| 4759 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4760 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4761 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4762 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4763 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4764 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4765 | } else { |
| 4766 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4767 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 4768 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4769 | // If read barriers are enabled, emit read barriers other than |
| 4770 | // Baker's using a slow path (and also unpoison the loaded |
| 4771 | // reference, if heap poisoning is enabled). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4772 | if (index.IsConstant()) { |
| 4773 | uint32_t offset = |
| 4774 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4775 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4776 | } else { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4777 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4778 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4779 | } |
| 4780 | } |
| 4781 | break; |
| 4782 | } |
| 4783 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4784 | case Primitive::kPrimLong: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4785 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4786 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4787 | break; |
| 4788 | } |
| 4789 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4790 | case Primitive::kPrimFloat: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4791 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4792 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4793 | break; |
| 4794 | } |
| 4795 | |
| 4796 | case Primitive::kPrimDouble: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4797 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4798 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4799 | break; |
| 4800 | } |
| 4801 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4802 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4803 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4804 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4805 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4806 | |
| 4807 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4808 | // Potential implicit null checks, in the case of reference |
| 4809 | // arrays, are handled in the previous switch statement. |
| 4810 | } else { |
| 4811 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4812 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4816 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4817 | |
| 4818 | bool needs_write_barrier = |
| 4819 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4820 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4821 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4822 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4823 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4824 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4825 | LocationSummary::kCallOnSlowPath : |
| 4826 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4827 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4828 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4829 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4830 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4831 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4832 | } else { |
| 4833 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4834 | } |
| 4835 | |
| 4836 | if (needs_write_barrier) { |
| 4837 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4838 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4839 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4840 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4841 | } |
| 4842 | |
| 4843 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4844 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4845 | Location array_loc = locations->InAt(0); |
| 4846 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4847 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4848 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4849 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4850 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4851 | bool needs_write_barrier = |
| 4852 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4853 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4854 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4855 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4856 | |
| 4857 | switch (value_type) { |
| 4858 | case Primitive::kPrimBoolean: |
| 4859 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4860 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4861 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4862 | if (value.IsRegister()) { |
| 4863 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4864 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4865 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4866 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4867 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4868 | break; |
| 4869 | } |
| 4870 | |
| 4871 | case Primitive::kPrimShort: |
| 4872 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4873 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4874 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4875 | if (value.IsRegister()) { |
| 4876 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4877 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4878 | DCHECK(value.IsConstant()) << value; |
| 4879 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4880 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4881 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4882 | break; |
| 4883 | } |
| 4884 | |
| 4885 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4886 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4887 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4888 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4889 | if (!value.IsRegister()) { |
| 4890 | // Just setting null. |
| 4891 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4892 | DCHECK(value.IsConstant()) << value; |
| 4893 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4894 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4895 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4896 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4897 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4898 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4899 | |
| 4900 | DCHECK(needs_write_barrier); |
| 4901 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4902 | // We cannot use a NearLabel for `done`, as its range may be too |
| 4903 | // short when Baker read barriers are enabled. |
| 4904 | Label done; |
| 4905 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4906 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4907 | Location temp_loc = locations->GetTemp(0); |
| 4908 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4909 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4910 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4911 | codegen_->AddSlowPath(slow_path); |
| 4912 | if (instruction->GetValueCanBeNull()) { |
| 4913 | __ testl(register_value, register_value); |
| 4914 | __ j(kNotEqual, ¬_null); |
| 4915 | __ movl(address, Immediate(0)); |
| 4916 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4917 | __ jmp(&done); |
| 4918 | __ Bind(¬_null); |
| 4919 | } |
| 4920 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4921 | // Note that when Baker read barriers are enabled, the type |
| 4922 | // checks are performed without read barriers. This is fine, |
| 4923 | // even in the case where a class object is in the from-space |
| 4924 | // after the flip, as a comparison involving such a type would |
| 4925 | // not produce a false positive; it may of course produce a |
| 4926 | // false negative, in which case we would take the ArraySet |
| 4927 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4928 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4929 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4930 | __ movl(temp, Address(array, class_offset)); |
| 4931 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4932 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4933 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4934 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4935 | __ movl(temp, Address(temp, component_offset)); |
| 4936 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4937 | // nor the object reference in `register_value->klass`, as |
| 4938 | // we are comparing two poisoned references. |
| 4939 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4940 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4941 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4942 | __ j(kEqual, &do_put); |
| 4943 | // If heap poisoning is enabled, the `temp` reference has |
| 4944 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4945 | __ MaybeUnpoisonHeapReference(temp); |
| 4946 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4947 | // If heap poisoning is enabled, no need to unpoison the |
| 4948 | // heap reference loaded below, as it is only used for a |
| 4949 | // comparison with null. |
| 4950 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 4951 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4952 | __ Bind(&do_put); |
| 4953 | } else { |
| 4954 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4955 | } |
| 4956 | } |
| 4957 | |
| 4958 | if (kPoisonHeapReferences) { |
| 4959 | __ movl(temp, register_value); |
| 4960 | __ PoisonHeapReference(temp); |
| 4961 | __ movl(address, temp); |
| 4962 | } else { |
| 4963 | __ movl(address, register_value); |
| 4964 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4965 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4966 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4967 | } |
| 4968 | |
| 4969 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4970 | codegen_->MarkGCCard( |
| 4971 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4972 | __ Bind(&done); |
| 4973 | |
| 4974 | if (slow_path != nullptr) { |
| 4975 | __ Bind(slow_path->GetExitLabel()); |
| 4976 | } |
| 4977 | |
| 4978 | break; |
| 4979 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4980 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4981 | case Primitive::kPrimInt: { |
| 4982 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4983 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4984 | if (value.IsRegister()) { |
| 4985 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4986 | } else { |
| 4987 | DCHECK(value.IsConstant()) << value; |
| 4988 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4989 | __ movl(address, Immediate(v)); |
| 4990 | } |
| 4991 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4992 | break; |
| 4993 | } |
| 4994 | |
| 4995 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4996 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4997 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4998 | if (value.IsRegister()) { |
| 4999 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5000 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5001 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5002 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5003 | Address address_high = |
| 5004 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5005 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5006 | } |
| 5007 | break; |
| 5008 | } |
| 5009 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5010 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5011 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5012 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5013 | if (value.IsFpuRegister()) { |
| 5014 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5015 | } else { |
| 5016 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5017 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5018 | __ movl(address, Immediate(v)); |
| 5019 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5020 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5021 | break; |
| 5022 | } |
| 5023 | |
| 5024 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5025 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5026 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5027 | if (value.IsFpuRegister()) { |
| 5028 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5029 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5030 | } else { |
| 5031 | int64_t v = |
| 5032 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5033 | Address address_high = |
| 5034 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5035 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5036 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5037 | break; |
| 5038 | } |
| 5039 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5040 | case Primitive::kPrimVoid: |
| 5041 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5042 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5043 | } |
| 5044 | } |
| 5045 | |
| 5046 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5047 | LocationSummary* locations = |
| 5048 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5049 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5050 | if (!instruction->IsEmittedAtUseSite()) { |
| 5051 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5052 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5053 | } |
| 5054 | |
| 5055 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5056 | if (instruction->IsEmittedAtUseSite()) { |
| 5057 | return; |
| 5058 | } |
| 5059 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5060 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5061 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5062 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5063 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5064 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5065 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5066 | // Mask out most significant bit in case the array is String's array of char. |
| 5067 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame^] | 5068 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5069 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5073 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5074 | InvokeRuntimeCallingConvention calling_convention; |
| 5075 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5076 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5077 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5078 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5079 | HInstruction* length = instruction->InputAt(1); |
| 5080 | if (!length->IsEmittedAtUseSite()) { |
| 5081 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5082 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5083 | } |
| 5084 | |
| 5085 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5086 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5087 | Location index_loc = locations->InAt(0); |
| 5088 | Location length_loc = locations->InAt(1); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5089 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5090 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5091 | if (length_loc.IsConstant()) { |
| 5092 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5093 | if (index_loc.IsConstant()) { |
| 5094 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5095 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5096 | if (index < 0 || index >= length) { |
| 5097 | codegen_->AddSlowPath(slow_path); |
| 5098 | __ jmp(slow_path->GetEntryLabel()); |
| 5099 | } else { |
| 5100 | // Some optimization after BCE may have generated this, and we should not |
| 5101 | // generate a bounds check if it is a valid range. |
| 5102 | } |
| 5103 | return; |
| 5104 | } |
| 5105 | |
| 5106 | // We have to reverse the jump condition because the length is the constant. |
| 5107 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5108 | __ cmpl(index_reg, Immediate(length)); |
| 5109 | codegen_->AddSlowPath(slow_path); |
| 5110 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5111 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5112 | HInstruction* array_length = instruction->InputAt(1); |
| 5113 | if (array_length->IsEmittedAtUseSite()) { |
| 5114 | // Address the length field in the array. |
| 5115 | DCHECK(array_length->IsArrayLength()); |
| 5116 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5117 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5118 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5119 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame^] | 5120 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5121 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5122 | CpuRegister length_reg = CpuRegister(TMP); |
| 5123 | __ movl(length_reg, array_len); |
| 5124 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame^] | 5125 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5126 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5127 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5128 | // Checking the bound for general case: |
| 5129 | // Array of char or String's array when the compression feature off. |
| 5130 | if (index_loc.IsConstant()) { |
| 5131 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5132 | __ cmpl(array_len, Immediate(value)); |
| 5133 | } else { |
| 5134 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5135 | } |
| 5136 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5137 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5138 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5139 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5140 | } |
| 5141 | codegen_->AddSlowPath(slow_path); |
| 5142 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5143 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5147 | CpuRegister card, |
| 5148 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5149 | CpuRegister value, |
| 5150 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5151 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5152 | if (value_can_be_null) { |
| 5153 | __ testl(value, value); |
| 5154 | __ j(kEqual, &is_null); |
| 5155 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5156 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5157 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5158 | __ movq(temp, object); |
| 5159 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5160 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5161 | if (value_can_be_null) { |
| 5162 | __ Bind(&is_null); |
| 5163 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5164 | } |
| 5165 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5166 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5167 | LOG(FATAL) << "Unimplemented"; |
| 5168 | } |
| 5169 | |
| 5170 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5171 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5172 | } |
| 5173 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5174 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5175 | LocationSummary* locations = |
| 5176 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5177 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5178 | } |
| 5179 | |
| 5180 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5181 | HBasicBlock* block = instruction->GetBlock(); |
| 5182 | if (block->GetLoopInformation() != nullptr) { |
| 5183 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5184 | // The back edge will generate the suspend check. |
| 5185 | return; |
| 5186 | } |
| 5187 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5188 | // The goto will generate the suspend check. |
| 5189 | return; |
| 5190 | } |
| 5191 | GenerateSuspendCheck(instruction, nullptr); |
| 5192 | } |
| 5193 | |
| 5194 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5195 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5196 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5197 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5198 | if (slow_path == nullptr) { |
| 5199 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5200 | instruction->SetSlowPath(slow_path); |
| 5201 | codegen_->AddSlowPath(slow_path); |
| 5202 | if (successor != nullptr) { |
| 5203 | DCHECK(successor->IsLoopHeader()); |
| 5204 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5205 | } |
| 5206 | } else { |
| 5207 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5208 | } |
| 5209 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5210 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5211 | /* no_rip */ true), |
| 5212 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5213 | if (successor == nullptr) { |
| 5214 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5215 | __ Bind(slow_path->GetReturnLabel()); |
| 5216 | } else { |
| 5217 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5218 | __ jmp(slow_path->GetEntryLabel()); |
| 5219 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5220 | } |
| 5221 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5222 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5223 | return codegen_->GetAssembler(); |
| 5224 | } |
| 5225 | |
| 5226 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5227 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5228 | Location source = move->GetSource(); |
| 5229 | Location destination = move->GetDestination(); |
| 5230 | |
| 5231 | if (source.IsRegister()) { |
| 5232 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5233 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5234 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5235 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5236 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5237 | } else { |
| 5238 | DCHECK(destination.IsDoubleStackSlot()); |
| 5239 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5240 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5241 | } |
| 5242 | } else if (source.IsStackSlot()) { |
| 5243 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5244 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5245 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5246 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5247 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5248 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5249 | } else { |
| 5250 | DCHECK(destination.IsStackSlot()); |
| 5251 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5252 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5253 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5254 | } else if (source.IsDoubleStackSlot()) { |
| 5255 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5256 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5257 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5258 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5259 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5260 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5261 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5262 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5263 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5264 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5265 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5266 | } else if (source.IsConstant()) { |
| 5267 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5268 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5269 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5270 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5271 | if (value == 0) { |
| 5272 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5273 | } else { |
| 5274 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5275 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5276 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5277 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5278 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5279 | } |
| 5280 | } else if (constant->IsLongConstant()) { |
| 5281 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5282 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5283 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5284 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5285 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5286 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5287 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5288 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5289 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5290 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5291 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5292 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5293 | } else { |
| 5294 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5295 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5296 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5297 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5298 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5299 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5300 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5301 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5302 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5303 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5304 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5305 | } else { |
| 5306 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5307 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5308 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5309 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5310 | } else if (source.IsFpuRegister()) { |
| 5311 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5312 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5313 | } else if (destination.IsStackSlot()) { |
| 5314 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5315 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5316 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5317 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5318 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5319 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5320 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5321 | } |
| 5322 | } |
| 5323 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5324 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5325 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5326 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5327 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5328 | } |
| 5329 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5330 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5331 | ScratchRegisterScope ensure_scratch( |
| 5332 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5333 | |
| 5334 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5335 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5336 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5337 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5338 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5339 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5340 | CpuRegister(ensure_scratch.GetRegister())); |
| 5341 | } |
| 5342 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5343 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5344 | __ movq(CpuRegister(TMP), reg1); |
| 5345 | __ movq(reg1, reg2); |
| 5346 | __ movq(reg2, CpuRegister(TMP)); |
| 5347 | } |
| 5348 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5349 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5350 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5351 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5352 | __ movq(reg, CpuRegister(TMP)); |
| 5353 | } |
| 5354 | |
| 5355 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5356 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5357 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5358 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5359 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5360 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5361 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5362 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5363 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5364 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5365 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5366 | } |
| 5367 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5368 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5369 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5370 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5371 | __ movd(reg, CpuRegister(TMP)); |
| 5372 | } |
| 5373 | |
| 5374 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5375 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5376 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5377 | __ movd(reg, CpuRegister(TMP)); |
| 5378 | } |
| 5379 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5380 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5381 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5382 | Location source = move->GetSource(); |
| 5383 | Location destination = move->GetDestination(); |
| 5384 | |
| 5385 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5386 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5387 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5388 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5389 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5390 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5391 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5392 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5393 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5394 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5395 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5396 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5397 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5398 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5399 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5400 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5401 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5402 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5403 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5404 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5405 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5406 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5407 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5408 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5409 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5410 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5411 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5412 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5413 | } |
| 5414 | } |
| 5415 | |
| 5416 | |
| 5417 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5418 | __ pushq(CpuRegister(reg)); |
| 5419 | } |
| 5420 | |
| 5421 | |
| 5422 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5423 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5424 | } |
| 5425 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5426 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5427 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5428 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5429 | Immediate(mirror::Class::kStatusInitialized)); |
| 5430 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5431 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5432 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5433 | } |
| 5434 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5435 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5436 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5437 | switch (desired_class_load_kind) { |
| 5438 | case HLoadClass::LoadKind::kReferrersClass: |
| 5439 | break; |
| 5440 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5441 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5442 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5443 | return HLoadClass::LoadKind::kBootImageLinkTimePcRelative; |
| 5444 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5445 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5446 | break; |
| 5447 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5448 | break; |
| 5449 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5450 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5451 | break; |
| 5452 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5453 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5454 | break; |
| 5455 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5456 | break; |
| 5457 | } |
| 5458 | return desired_class_load_kind; |
| 5459 | } |
| 5460 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5461 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5462 | if (cls->NeedsAccessCheck()) { |
| 5463 | InvokeRuntimeCallingConvention calling_convention; |
| 5464 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5465 | cls, |
| 5466 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5467 | Location::RegisterLocation(RAX), |
| 5468 | /* code_generator_supports_read_barrier */ true); |
| 5469 | return; |
| 5470 | } |
| 5471 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5472 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5473 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5474 | ? LocationSummary::kCallOnSlowPath |
| 5475 | : LocationSummary::kNoCall; |
| 5476 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5477 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5478 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5479 | } |
| 5480 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5481 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5482 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5483 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5484 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5485 | } |
| 5486 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5487 | } |
| 5488 | |
| 5489 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5490 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5491 | if (cls->NeedsAccessCheck()) { |
| 5492 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5493 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5494 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5495 | return; |
| 5496 | } |
| 5497 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5498 | Location out_loc = locations->Out(); |
| 5499 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5500 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5501 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5502 | bool generate_null_check = false; |
| 5503 | switch (cls->GetLoadKind()) { |
| 5504 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5505 | DCHECK(!cls->CanCallRuntime()); |
| 5506 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5507 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5508 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5509 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5510 | cls, |
| 5511 | out_loc, |
| 5512 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5513 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5514 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5515 | break; |
| 5516 | } |
| 5517 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5518 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5519 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5520 | codegen_->RecordTypePatch(cls); |
| 5521 | break; |
| 5522 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5523 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5524 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5525 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5526 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5527 | codegen_->RecordSimplePatch(); |
| 5528 | break; |
| 5529 | } |
| 5530 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5531 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5532 | // /* GcRoot<mirror::Class> */ out = *address |
| 5533 | if (IsUint<32>(cls->GetAddress())) { |
| 5534 | Address address = Address::Absolute(cls->GetAddress(), /* no_rip */ true); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5535 | GenerateGcRootFieldLoad(cls, |
| 5536 | out_loc, |
| 5537 | address, |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5538 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5539 | requires_read_barrier); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5540 | } else { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5541 | // TODO: Consider using opcode A1, i.e. movl eax, moff32 (with 64-bit address). |
| 5542 | __ movq(out, Immediate(cls->GetAddress())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5543 | GenerateGcRootFieldLoad(cls, |
| 5544 | out_loc, |
| 5545 | Address(out, 0), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5546 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5547 | requires_read_barrier); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5548 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5549 | generate_null_check = !cls->IsInDexCache(); |
| 5550 | break; |
| 5551 | } |
| 5552 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5553 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 5554 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 5555 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5556 | /* no_rip */ false); |
| 5557 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5558 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5559 | generate_null_check = !cls->IsInDexCache(); |
| 5560 | break; |
| 5561 | } |
| 5562 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5563 | // /* GcRoot<mirror::Class>[] */ out = |
| 5564 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5565 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5566 | __ movq(out, |
| 5567 | Address(current_method, |
| 5568 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
| 5569 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5570 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5571 | cls, |
| 5572 | out_loc, |
| 5573 | Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())), |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5574 | /* fixup_label */ nullptr, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5575 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5576 | generate_null_check = !cls->IsInDexCache(); |
| 5577 | break; |
| 5578 | } |
| 5579 | default: |
| 5580 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5581 | UNREACHABLE(); |
| 5582 | } |
| 5583 | |
| 5584 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5585 | DCHECK(cls->CanCallRuntime()); |
| 5586 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5587 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5588 | codegen_->AddSlowPath(slow_path); |
| 5589 | if (generate_null_check) { |
| 5590 | __ testl(out, out); |
| 5591 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5592 | } |
| 5593 | if (cls->MustGenerateClinitCheck()) { |
| 5594 | GenerateClassInitializationCheck(slow_path, out); |
| 5595 | } else { |
| 5596 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5597 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5598 | } |
| 5599 | } |
| 5600 | |
| 5601 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5602 | LocationSummary* locations = |
| 5603 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5604 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5605 | if (check->HasUses()) { |
| 5606 | locations->SetOut(Location::SameAsFirstInput()); |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5611 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5612 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5613 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5614 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5615 | GenerateClassInitializationCheck(slow_path, |
| 5616 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5617 | } |
| 5618 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5619 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5620 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5621 | switch (desired_string_load_kind) { |
| 5622 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5623 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5624 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5625 | return HLoadString::LoadKind::kBootImageLinkTimePcRelative; |
| 5626 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5627 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5628 | break; |
| 5629 | case HLoadString::LoadKind::kBootImageAddress: |
| 5630 | break; |
| 5631 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5632 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5633 | break; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5634 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5635 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5636 | break; |
| 5637 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5638 | break; |
| 5639 | } |
| 5640 | return desired_string_load_kind; |
| 5641 | } |
| 5642 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5643 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5644 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5645 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 5646 | ? LocationSummary::kCallOnMainOnly |
| 5647 | : LocationSummary::kCallOnSlowPath) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5648 | : LocationSummary::kNoCall; |
| 5649 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5650 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5651 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 5652 | } else { |
| 5653 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 5654 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 5655 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5656 | // Rely on the pResolveString and/or marking to save everything. |
| 5657 | // Custom calling convention: RAX serves as both input and output. |
| 5658 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5659 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5660 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5661 | } else { |
| 5662 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5663 | } |
| 5664 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5665 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5666 | } |
| 5667 | |
| 5668 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5669 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5670 | Location out_loc = locations->Out(); |
| 5671 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5672 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5673 | switch (load->GetLoadKind()) { |
| 5674 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5675 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5676 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5677 | return; // No dex cache slow path. |
| 5678 | } |
| 5679 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5680 | DCHECK_NE(load->GetAddress(), 0u); |
| 5681 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5682 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5683 | codegen_->RecordSimplePatch(); |
| 5684 | return; // No dex cache slow path. |
| 5685 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5686 | case HLoadString::LoadKind::kBssEntry: { |
| 5687 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5688 | /* no_rip */ false); |
| 5689 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 5690 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5691 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kEmitCompilerReadBarrier); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5692 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5693 | codegen_->AddSlowPath(slow_path); |
| 5694 | __ testl(out, out); |
| 5695 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5696 | __ Bind(slow_path->GetExitLabel()); |
| 5697 | return; |
| 5698 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5699 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5700 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5701 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5702 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5703 | // 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] | 5704 | // Custom calling convention: RAX serves as both input and output. |
| 5705 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex())); |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5706 | codegen_->InvokeRuntime(kQuickResolveString, |
| 5707 | load, |
| 5708 | load->GetDexPc()); |
| 5709 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5710 | } |
| 5711 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5712 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5713 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5714 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5715 | } |
| 5716 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5717 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5718 | LocationSummary* locations = |
| 5719 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5720 | locations->SetOut(Location::RequiresRegister()); |
| 5721 | } |
| 5722 | |
| 5723 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5724 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5725 | } |
| 5726 | |
| 5727 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5728 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5729 | } |
| 5730 | |
| 5731 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5732 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5733 | } |
| 5734 | |
| 5735 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5736 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5737 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5738 | InvokeRuntimeCallingConvention calling_convention; |
| 5739 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5740 | } |
| 5741 | |
| 5742 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5743 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5744 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5745 | } |
| 5746 | |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5747 | static bool CheckCastTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5748 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 5749 | // We need a temporary for holding the iftable length. |
| 5750 | return true; |
| 5751 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5752 | return kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5753 | !kUseBakerReadBarrier && |
| 5754 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5755 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5756 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5757 | } |
| 5758 | |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5759 | static bool InstanceOfTypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5760 | return kEmitCompilerReadBarrier && |
| 5761 | !kUseBakerReadBarrier && |
| 5762 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5763 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5764 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5765 | } |
| 5766 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5767 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5768 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5769 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5770 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5771 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5772 | case TypeCheckKind::kExactCheck: |
| 5773 | case TypeCheckKind::kAbstractClassCheck: |
| 5774 | case TypeCheckKind::kClassHierarchyCheck: |
| 5775 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5776 | call_kind = |
| 5777 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5778 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5779 | break; |
| 5780 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5781 | case TypeCheckKind::kUnresolvedCheck: |
| 5782 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5783 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5784 | break; |
| 5785 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5786 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5787 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5788 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5789 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5790 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5791 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5792 | locations->SetInAt(1, Location::Any()); |
| 5793 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5794 | locations->SetOut(Location::RequiresRegister()); |
| 5795 | // When read barriers are enabled, we need a temporary register for |
| 5796 | // some cases. |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5797 | if (InstanceOfTypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5798 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5799 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5800 | } |
| 5801 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5802 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5803 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5804 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5805 | Location obj_loc = locations->InAt(0); |
| 5806 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5807 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5808 | Location out_loc = locations->Out(); |
| 5809 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 5810 | Location maybe_temp_loc = InstanceOfTypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5811 | locations->GetTemp(0) : |
| 5812 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5813 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5814 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5815 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5816 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5817 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5818 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5819 | |
| 5820 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5821 | // Avoid null check if we know obj is not null. |
| 5822 | if (instruction->MustDoNullCheck()) { |
| 5823 | __ testl(obj, obj); |
| 5824 | __ j(kEqual, &zero); |
| 5825 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5826 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5827 | // /* HeapReference<Class> */ out = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 5828 | GenerateReferenceLoadTwoRegisters(instruction, |
| 5829 | out_loc, |
| 5830 | obj_loc, |
| 5831 | class_offset, |
| 5832 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5833 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5834 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5835 | case TypeCheckKind::kExactCheck: { |
| 5836 | if (cls.IsRegister()) { |
| 5837 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5838 | } else { |
| 5839 | DCHECK(cls.IsStackSlot()) << cls; |
| 5840 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5841 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5842 | if (zero.IsLinked()) { |
| 5843 | // Classes must be equal for the instanceof to succeed. |
| 5844 | __ j(kNotEqual, &zero); |
| 5845 | __ movl(out, Immediate(1)); |
| 5846 | __ jmp(&done); |
| 5847 | } else { |
| 5848 | __ setcc(kEqual, out); |
| 5849 | // setcc only sets the low byte. |
| 5850 | __ andl(out, Immediate(1)); |
| 5851 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5852 | break; |
| 5853 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5854 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5855 | case TypeCheckKind::kAbstractClassCheck: { |
| 5856 | // If the class is abstract, we eagerly fetch the super class of the |
| 5857 | // object to avoid doing a comparison we know will fail. |
| 5858 | NearLabel loop, success; |
| 5859 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5860 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5861 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5862 | __ testl(out, out); |
| 5863 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5864 | __ j(kEqual, &done); |
| 5865 | if (cls.IsRegister()) { |
| 5866 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5867 | } else { |
| 5868 | DCHECK(cls.IsStackSlot()) << cls; |
| 5869 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5870 | } |
| 5871 | __ j(kNotEqual, &loop); |
| 5872 | __ movl(out, Immediate(1)); |
| 5873 | if (zero.IsLinked()) { |
| 5874 | __ jmp(&done); |
| 5875 | } |
| 5876 | break; |
| 5877 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5878 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5879 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5880 | // Walk over the class hierarchy to find a match. |
| 5881 | NearLabel loop, success; |
| 5882 | __ Bind(&loop); |
| 5883 | if (cls.IsRegister()) { |
| 5884 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5885 | } else { |
| 5886 | DCHECK(cls.IsStackSlot()) << cls; |
| 5887 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5888 | } |
| 5889 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5890 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5891 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5892 | __ testl(out, out); |
| 5893 | __ j(kNotEqual, &loop); |
| 5894 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5895 | __ jmp(&done); |
| 5896 | __ Bind(&success); |
| 5897 | __ movl(out, Immediate(1)); |
| 5898 | if (zero.IsLinked()) { |
| 5899 | __ jmp(&done); |
| 5900 | } |
| 5901 | break; |
| 5902 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5903 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5904 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5905 | // Do an exact check. |
| 5906 | NearLabel exact_check; |
| 5907 | if (cls.IsRegister()) { |
| 5908 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5909 | } else { |
| 5910 | DCHECK(cls.IsStackSlot()) << cls; |
| 5911 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5912 | } |
| 5913 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5914 | // 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] | 5915 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5916 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5917 | __ testl(out, out); |
| 5918 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5919 | __ j(kEqual, &done); |
| 5920 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5921 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5922 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5923 | __ movl(out, Immediate(1)); |
| 5924 | __ jmp(&done); |
| 5925 | break; |
| 5926 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5927 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5928 | case TypeCheckKind::kArrayCheck: { |
| 5929 | if (cls.IsRegister()) { |
| 5930 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5931 | } else { |
| 5932 | DCHECK(cls.IsStackSlot()) << cls; |
| 5933 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5934 | } |
| 5935 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5936 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5937 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5938 | codegen_->AddSlowPath(slow_path); |
| 5939 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5940 | __ movl(out, Immediate(1)); |
| 5941 | if (zero.IsLinked()) { |
| 5942 | __ jmp(&done); |
| 5943 | } |
| 5944 | break; |
| 5945 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5946 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5947 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5948 | case TypeCheckKind::kInterfaceCheck: { |
| 5949 | // 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] | 5950 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5951 | // cases. |
| 5952 | // |
| 5953 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5954 | // entry point without resorting to a type checking slow path |
| 5955 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5956 | // require to assign fixed registers for the inputs of this |
| 5957 | // HInstanceOf instruction (following the runtime calling |
| 5958 | // convention), which might be cluttered by the potential first |
| 5959 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5960 | // |
| 5961 | // TODO: Introduce a new runtime entry point taking the object |
| 5962 | // to test (instead of its class) as argument, and let it deal |
| 5963 | // with the read barrier issues. This will let us refactor this |
| 5964 | // case of the `switch` code as it was previously (with a direct |
| 5965 | // call to the runtime not using a type checking slow path). |
| 5966 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5967 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5968 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5969 | /* is_fatal */ false); |
| 5970 | codegen_->AddSlowPath(slow_path); |
| 5971 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5972 | if (zero.IsLinked()) { |
| 5973 | __ jmp(&done); |
| 5974 | } |
| 5975 | break; |
| 5976 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5977 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5978 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5979 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5980 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5981 | __ xorl(out, out); |
| 5982 | } |
| 5983 | |
| 5984 | if (done.IsLinked()) { |
| 5985 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5986 | } |
| 5987 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5988 | if (slow_path != nullptr) { |
| 5989 | __ Bind(slow_path->GetExitLabel()); |
| 5990 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5991 | } |
| 5992 | |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 5993 | bool IsTypeCheckSlowPathFatal(TypeCheckKind type_check_kind, bool throws_into_catch) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5994 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5995 | case TypeCheckKind::kExactCheck: |
| 5996 | case TypeCheckKind::kAbstractClassCheck: |
| 5997 | case TypeCheckKind::kClassHierarchyCheck: |
| 5998 | case TypeCheckKind::kArrayObjectCheck: |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 5999 | return !throws_into_catch && !kEmitCompilerReadBarrier; |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6000 | case TypeCheckKind::kInterfaceCheck: |
| 6001 | return !throws_into_catch && !kEmitCompilerReadBarrier && !kPoisonHeapReferences; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6002 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6003 | case TypeCheckKind::kUnresolvedCheck: |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6004 | return false; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6005 | } |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6006 | LOG(FATAL) << "Unreachable"; |
| 6007 | UNREACHABLE(); |
| 6008 | } |
| 6009 | |
| 6010 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 6011 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 6012 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6013 | bool is_fatal_slow_path = IsTypeCheckSlowPathFatal(type_check_kind, throws_into_catch); |
| 6014 | LocationSummary::CallKind call_kind = is_fatal_slow_path |
| 6015 | ? LocationSummary::kNoCall |
| 6016 | : LocationSummary::kCallOnSlowPath; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6017 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6018 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6019 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6020 | // Require a register for the interface check since there is a loop that compares the class to |
| 6021 | // a memory address. |
| 6022 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6023 | } else { |
| 6024 | locations->SetInAt(1, Location::Any()); |
| 6025 | } |
| 6026 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6027 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 6028 | locations->AddTemp(Location::RequiresRegister()); |
| 6029 | // When read barriers are enabled, we need an additional temporary |
| 6030 | // register for some cases. |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6031 | if (CheckCastTypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6032 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6033 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6034 | } |
| 6035 | |
| 6036 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6037 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6038 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6039 | Location obj_loc = locations->InAt(0); |
| 6040 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6041 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6042 | Location temp_loc = locations->GetTemp(0); |
| 6043 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6044 | Location maybe_temp2_loc = CheckCastTypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6045 | locations->GetTemp(1) : |
| 6046 | Location::NoLocation(); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6047 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6048 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6049 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6050 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6051 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6052 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 6053 | const int object_array_data_offset = mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6054 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6055 | bool is_type_check_slow_path_fatal = |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6056 | IsTypeCheckSlowPathFatal(type_check_kind, instruction->CanThrowIntoCatchBlock()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6057 | SlowPathCode* type_check_slow_path = |
| 6058 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 6059 | is_type_check_slow_path_fatal); |
| 6060 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6061 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6062 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6063 | case TypeCheckKind::kExactCheck: |
| 6064 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6065 | NearLabel done; |
| 6066 | // Avoid null check if we know obj is not null. |
| 6067 | if (instruction->MustDoNullCheck()) { |
| 6068 | __ testl(obj, obj); |
| 6069 | __ j(kEqual, &done); |
| 6070 | } |
| 6071 | |
| 6072 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6073 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6074 | temp_loc, |
| 6075 | obj_loc, |
| 6076 | class_offset, |
| 6077 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6078 | if (cls.IsRegister()) { |
| 6079 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6080 | } else { |
| 6081 | DCHECK(cls.IsStackSlot()) << cls; |
| 6082 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6083 | } |
| 6084 | // Jump to slow path for throwing the exception or doing a |
| 6085 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6086 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6087 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6088 | break; |
| 6089 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6090 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6091 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6092 | NearLabel done; |
| 6093 | // Avoid null check if we know obj is not null. |
| 6094 | if (instruction->MustDoNullCheck()) { |
| 6095 | __ testl(obj, obj); |
| 6096 | __ j(kEqual, &done); |
| 6097 | } |
| 6098 | |
| 6099 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6100 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6101 | temp_loc, |
| 6102 | obj_loc, |
| 6103 | class_offset, |
| 6104 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6105 | // If the class is abstract, we eagerly fetch the super class of the |
| 6106 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6107 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6108 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6109 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6110 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6111 | |
| 6112 | // If the class reference currently in `temp` is not null, jump |
| 6113 | // to the `compare_classes` label to compare it with the checked |
| 6114 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6115 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6116 | __ j(kNotEqual, &compare_classes); |
| 6117 | // Otherwise, jump to the slow path to throw the exception. |
| 6118 | // |
| 6119 | // But before, move back the object's class into `temp` before |
| 6120 | // going into the slow path, as it has been overwritten in the |
| 6121 | // meantime. |
| 6122 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6123 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6124 | temp_loc, |
| 6125 | obj_loc, |
| 6126 | class_offset, |
| 6127 | kEmitCompilerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6128 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6129 | |
| 6130 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6131 | if (cls.IsRegister()) { |
| 6132 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6133 | } else { |
| 6134 | DCHECK(cls.IsStackSlot()) << cls; |
| 6135 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6136 | } |
| 6137 | __ j(kNotEqual, &loop); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6138 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6139 | break; |
| 6140 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6141 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6142 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6143 | NearLabel done; |
| 6144 | // Avoid null check if we know obj is not null. |
| 6145 | if (instruction->MustDoNullCheck()) { |
| 6146 | __ testl(obj, obj); |
| 6147 | __ j(kEqual, &done); |
| 6148 | } |
| 6149 | |
| 6150 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6151 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6152 | temp_loc, |
| 6153 | obj_loc, |
| 6154 | class_offset, |
| 6155 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6156 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6157 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6158 | __ Bind(&loop); |
| 6159 | if (cls.IsRegister()) { |
| 6160 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6161 | } else { |
| 6162 | DCHECK(cls.IsStackSlot()) << cls; |
| 6163 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6164 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6165 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6166 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6167 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6168 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6169 | |
| 6170 | // If the class reference currently in `temp` is not null, jump |
| 6171 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6172 | __ testl(temp, temp); |
| 6173 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6174 | // Otherwise, jump to the slow path to throw the exception. |
| 6175 | // |
| 6176 | // But before, move back the object's class into `temp` before |
| 6177 | // going into the slow path, as it has been overwritten in the |
| 6178 | // meantime. |
| 6179 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6180 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6181 | temp_loc, |
| 6182 | obj_loc, |
| 6183 | class_offset, |
| 6184 | kEmitCompilerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6185 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6186 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6187 | break; |
| 6188 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6189 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6190 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6191 | // We cannot use a NearLabel here, as its range might be too |
| 6192 | // short in some cases when read barriers are enabled. This has |
| 6193 | // been observed for instance when the code emitted for this |
| 6194 | // case uses high x86-64 registers (R8-R15). |
| 6195 | Label done; |
| 6196 | // Avoid null check if we know obj is not null. |
| 6197 | if (instruction->MustDoNullCheck()) { |
| 6198 | __ testl(obj, obj); |
| 6199 | __ j(kEqual, &done); |
| 6200 | } |
| 6201 | |
| 6202 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6203 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6204 | temp_loc, |
| 6205 | obj_loc, |
| 6206 | class_offset, |
| 6207 | kEmitCompilerReadBarrier); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6208 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6209 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6210 | if (cls.IsRegister()) { |
| 6211 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6212 | } else { |
| 6213 | DCHECK(cls.IsStackSlot()) << cls; |
| 6214 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6215 | } |
| 6216 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6217 | |
| 6218 | // 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] | 6219 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6220 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6221 | |
| 6222 | // If the component type is not null (i.e. the object is indeed |
| 6223 | // an array), jump to label `check_non_primitive_component_type` |
| 6224 | // to further check that this component type is not a primitive |
| 6225 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6226 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6227 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6228 | // Otherwise, jump to the slow path to throw the exception. |
| 6229 | // |
| 6230 | // But before, move back the object's class into `temp` before |
| 6231 | // going into the slow path, as it has been overwritten in the |
| 6232 | // meantime. |
| 6233 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6234 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6235 | temp_loc, |
| 6236 | obj_loc, |
| 6237 | class_offset, |
| 6238 | kEmitCompilerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6239 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6240 | |
| 6241 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6242 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6243 | __ j(kEqual, &done); |
| 6244 | // Same comment as above regarding `temp` and the slow path. |
| 6245 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6246 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6247 | temp_loc, |
| 6248 | obj_loc, |
| 6249 | class_offset, |
| 6250 | kEmitCompilerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6251 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6252 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6253 | break; |
| 6254 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6255 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6256 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6257 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6258 | NearLabel done; |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6259 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6260 | // Avoid null check if we know obj is not null. |
| 6261 | if (instruction->MustDoNullCheck()) { |
| 6262 | __ testl(obj, obj); |
| 6263 | __ j(kEqual, &done); |
| 6264 | } |
| 6265 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6266 | |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6267 | // 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] | 6268 | // |
| 6269 | // We cannot directly call the CheckCast runtime entry point |
| 6270 | // without resorting to a type checking slow path here (i.e. by |
| 6271 | // calling InvokeRuntime directly), as it would require to |
| 6272 | // assign fixed registers for the inputs of this HInstanceOf |
| 6273 | // instruction (following the runtime calling convention), which |
| 6274 | // might be cluttered by the potential first read barrier |
| 6275 | // emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6276 | // |
| 6277 | // TODO: Introduce a new runtime entry point taking the object |
| 6278 | // to test (instead of its class) as argument, and let it deal |
| 6279 | // with the read barrier issues. This will let us refactor this |
| 6280 | // case of the `switch` code as it was previously (with a direct |
| 6281 | // call to the runtime not using a type checking slow path). |
| 6282 | // This should also be beneficial for the other cases above. |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6283 | |
| 6284 | // Fast path for the interface check. Since we compare with a memory location in the inner |
| 6285 | // loop we would need to have cls poisoned. However unpoisoning cls would reset the |
| 6286 | // conditional flags and cause the conditional jump to be incorrect. |
| 6287 | if (type_check_kind == TypeCheckKind::kInterfaceCheck && !kPoisonHeapReferences) { |
| 6288 | // Try to avoid read barriers to improve the fast path. We can not get false positives by |
| 6289 | // doing this. |
| 6290 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6291 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6292 | temp_loc, |
| 6293 | obj_loc, |
| 6294 | class_offset, |
| 6295 | /*emit_read_barrier*/ false); |
| 6296 | |
| 6297 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6298 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6299 | temp_loc, |
| 6300 | temp_loc, |
| 6301 | iftable_offset, |
| 6302 | /*emit_read_barrier*/ false); |
| 6303 | NearLabel is_null; |
| 6304 | // Null iftable means it is empty. |
| 6305 | __ testl(temp_loc.AsRegister<CpuRegister>(), temp_loc.AsRegister<CpuRegister>()); |
| 6306 | __ j(kZero, &is_null); |
| 6307 | |
| 6308 | // Loop through the iftable and check if any class matches. |
| 6309 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), |
| 6310 | Address(temp_loc.AsRegister<CpuRegister>(), array_length_offset)); |
| 6311 | |
| 6312 | NearLabel start_loop; |
| 6313 | __ Bind(&start_loop); |
| 6314 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 6315 | Address(temp_loc.AsRegister<CpuRegister>(), object_array_data_offset)); |
| 6316 | __ j(kEqual, &done); // Return if same class. |
| 6317 | // Go to next interface. |
| 6318 | __ addq(temp_loc.AsRegister<CpuRegister>(), Immediate(2 * kHeapReferenceSize)); |
| 6319 | __ subq(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| 6320 | __ j(kNotZero, &start_loop); |
| 6321 | __ Bind(&is_null); |
| 6322 | } |
| 6323 | |
| 6324 | // Since we clobbered temp_loc holding the class, we need to reload it. |
| 6325 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6326 | temp_loc, |
| 6327 | obj_loc, |
| 6328 | class_offset, |
| 6329 | kEmitCompilerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6330 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6331 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6332 | break; |
| 6333 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6334 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6335 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6336 | } |
| 6337 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6338 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6339 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6340 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6341 | InvokeRuntimeCallingConvention calling_convention; |
| 6342 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6343 | } |
| 6344 | |
| 6345 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6346 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6347 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6348 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6349 | if (instruction->IsEnter()) { |
| 6350 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6351 | } else { |
| 6352 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6353 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6354 | } |
| 6355 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6356 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6357 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6358 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6359 | |
| 6360 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6361 | LocationSummary* locations = |
| 6362 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6363 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6364 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6365 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6366 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6367 | locations->SetOut(Location::SameAsFirstInput()); |
| 6368 | } |
| 6369 | |
| 6370 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6371 | HandleBitwiseOperation(instruction); |
| 6372 | } |
| 6373 | |
| 6374 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6375 | HandleBitwiseOperation(instruction); |
| 6376 | } |
| 6377 | |
| 6378 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6379 | HandleBitwiseOperation(instruction); |
| 6380 | } |
| 6381 | |
| 6382 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6383 | LocationSummary* locations = instruction->GetLocations(); |
| 6384 | Location first = locations->InAt(0); |
| 6385 | Location second = locations->InAt(1); |
| 6386 | DCHECK(first.Equals(locations->Out())); |
| 6387 | |
| 6388 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6389 | if (second.IsRegister()) { |
| 6390 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6391 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6392 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6393 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6394 | } else { |
| 6395 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6396 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6397 | } |
| 6398 | } else if (second.IsConstant()) { |
| 6399 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6400 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6401 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6402 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6403 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6404 | } else { |
| 6405 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6406 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6407 | } |
| 6408 | } else { |
| 6409 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6410 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6411 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6412 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6413 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6414 | } else { |
| 6415 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6416 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6417 | } |
| 6418 | } |
| 6419 | } else { |
| 6420 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6421 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6422 | bool second_is_constant = false; |
| 6423 | int64_t value = 0; |
| 6424 | if (second.IsConstant()) { |
| 6425 | second_is_constant = true; |
| 6426 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6427 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6428 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6429 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6430 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6431 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6432 | if (is_int32_value) { |
| 6433 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6434 | } else { |
| 6435 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6436 | } |
| 6437 | } else if (second.IsDoubleStackSlot()) { |
| 6438 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6439 | } else { |
| 6440 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6441 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6442 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6443 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6444 | if (is_int32_value) { |
| 6445 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6446 | } else { |
| 6447 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6448 | } |
| 6449 | } else if (second.IsDoubleStackSlot()) { |
| 6450 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6451 | } else { |
| 6452 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6453 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6454 | } else { |
| 6455 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6456 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6457 | if (is_int32_value) { |
| 6458 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6459 | } else { |
| 6460 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6461 | } |
| 6462 | } else if (second.IsDoubleStackSlot()) { |
| 6463 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6464 | } else { |
| 6465 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6466 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6467 | } |
| 6468 | } |
| 6469 | } |
| 6470 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6471 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6472 | Location out, |
| 6473 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6474 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6475 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6476 | if (kEmitCompilerReadBarrier) { |
| 6477 | if (kUseBakerReadBarrier) { |
| 6478 | // Load with fast path based Baker's read barrier. |
| 6479 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6480 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6481 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6482 | } else { |
| 6483 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6484 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6485 | // in the following move operation, as we will need it for the |
| 6486 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6487 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6488 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6489 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6490 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6491 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6492 | } |
| 6493 | } else { |
| 6494 | // Plain load with no read barrier. |
| 6495 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6496 | __ movl(out_reg, Address(out_reg, offset)); |
| 6497 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6498 | } |
| 6499 | } |
| 6500 | |
| 6501 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6502 | Location out, |
| 6503 | Location obj, |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6504 | uint32_t offset, |
| 6505 | bool emit_read_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6506 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6507 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6508 | if (emit_read_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6509 | if (kUseBakerReadBarrier) { |
| 6510 | // Load with fast path based Baker's read barrier. |
| 6511 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6512 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6513 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6514 | } else { |
| 6515 | // Load with slow path based read barrier. |
| 6516 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6517 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6518 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6519 | } |
| 6520 | } else { |
| 6521 | // Plain load with no read barrier. |
| 6522 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6523 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6524 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6525 | } |
| 6526 | } |
| 6527 | |
| 6528 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6529 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6530 | const Address& address, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6531 | Label* fixup_label, |
| 6532 | bool requires_read_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6533 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6534 | if (requires_read_barrier) { |
| 6535 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6536 | if (kUseBakerReadBarrier) { |
| 6537 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6538 | // Baker's read barrier are used: |
| 6539 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6540 | // root = *address; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6541 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6542 | // root = ReadBarrier::Mark(root) |
| 6543 | // } |
| 6544 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6545 | // /* GcRoot<mirror::Object> */ root = *address |
| 6546 | __ movl(root_reg, address); |
| 6547 | if (fixup_label != nullptr) { |
| 6548 | __ Bind(fixup_label); |
| 6549 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6550 | static_assert( |
| 6551 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6552 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6553 | "have different sizes."); |
| 6554 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6555 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6556 | "have different sizes."); |
| 6557 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6558 | // Slow path marking the GC root `root`. |
| 6559 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6560 | instruction, root, /* unpoison_ref_before_marking */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6561 | codegen_->AddSlowPath(slow_path); |
| 6562 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6563 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6564 | /* no_rip */ true), |
| 6565 | Immediate(0)); |
| 6566 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6567 | __ Bind(slow_path->GetExitLabel()); |
| 6568 | } else { |
| 6569 | // GC root loaded through a slow path for read barriers other |
| 6570 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6571 | // /* GcRoot<mirror::Object>* */ root = address |
| 6572 | __ leaq(root_reg, address); |
| 6573 | if (fixup_label != nullptr) { |
| 6574 | __ Bind(fixup_label); |
| 6575 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6576 | // /* mirror::Object* */ root = root->Read() |
| 6577 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6578 | } |
| 6579 | } else { |
| 6580 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6581 | // /* GcRoot<mirror::Object> */ root = *address |
| 6582 | __ movl(root_reg, address); |
| 6583 | if (fixup_label != nullptr) { |
| 6584 | __ Bind(fixup_label); |
| 6585 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6586 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6587 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6588 | } |
| 6589 | } |
| 6590 | |
| 6591 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6592 | Location ref, |
| 6593 | CpuRegister obj, |
| 6594 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6595 | bool needs_null_check) { |
| 6596 | DCHECK(kEmitCompilerReadBarrier); |
| 6597 | DCHECK(kUseBakerReadBarrier); |
| 6598 | |
| 6599 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6600 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6601 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6602 | } |
| 6603 | |
| 6604 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6605 | Location ref, |
| 6606 | CpuRegister obj, |
| 6607 | uint32_t data_offset, |
| 6608 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6609 | bool needs_null_check) { |
| 6610 | DCHECK(kEmitCompilerReadBarrier); |
| 6611 | DCHECK(kUseBakerReadBarrier); |
| 6612 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6613 | static_assert( |
| 6614 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6615 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6616 | // /* HeapReference<Object> */ ref = |
| 6617 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6618 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6619 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6620 | } |
| 6621 | |
| 6622 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6623 | Location ref, |
| 6624 | CpuRegister obj, |
| 6625 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6626 | bool needs_null_check, |
| 6627 | bool always_update_field, |
| 6628 | CpuRegister* temp1, |
| 6629 | CpuRegister* temp2) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6630 | DCHECK(kEmitCompilerReadBarrier); |
| 6631 | DCHECK(kUseBakerReadBarrier); |
| 6632 | |
| 6633 | // In slow path based read barriers, the read barrier call is |
| 6634 | // inserted after the original load. However, in fast path based |
| 6635 | // Baker's read barriers, we need to perform the load of |
| 6636 | // mirror::Object::monitor_ *before* the original reference load. |
| 6637 | // This load-load ordering is required by the read barrier. |
| 6638 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6639 | // |
| 6640 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6641 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6642 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6643 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6644 | // if (is_gray) { |
| 6645 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6646 | // } |
| 6647 | // |
| 6648 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6649 | // slightly more complex as: |
| 6650 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6651 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6652 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6653 | // 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] | 6654 | // - it performs additional checks that we do not do here for |
| 6655 | // performance reasons. |
| 6656 | |
| 6657 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6658 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6659 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6660 | // 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] | 6661 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 6662 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6663 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6664 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6665 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6666 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 6667 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6668 | // ref = ReadBarrier::Mark(ref); |
| 6669 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6670 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6671 | if (needs_null_check) { |
| 6672 | MaybeRecordImplicitNullCheck(instruction); |
| 6673 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6674 | |
| 6675 | // Load fence to prevent load-load reordering. |
| 6676 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6677 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6678 | |
| 6679 | // The actual reference load. |
| 6680 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6681 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6682 | |
| 6683 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6684 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6685 | SlowPathCode* slow_path; |
| 6686 | if (always_update_field) { |
| 6687 | DCHECK(temp1 != nullptr); |
| 6688 | DCHECK(temp2 != nullptr); |
| 6689 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
| 6690 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp1, *temp2); |
| 6691 | } else { |
| 6692 | slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6693 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 6694 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6695 | AddSlowPath(slow_path); |
| 6696 | |
| 6697 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6698 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6699 | |
| 6700 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6701 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6702 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6703 | __ Bind(slow_path->GetExitLabel()); |
| 6704 | } |
| 6705 | |
| 6706 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6707 | Location out, |
| 6708 | Location ref, |
| 6709 | Location obj, |
| 6710 | uint32_t offset, |
| 6711 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6712 | DCHECK(kEmitCompilerReadBarrier); |
| 6713 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6714 | // Insert a slow path based read barrier *after* the reference load. |
| 6715 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6716 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6717 | // reference will be carried out by the runtime within the slow |
| 6718 | // path. |
| 6719 | // |
| 6720 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6721 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6722 | // not used by the artReadBarrierSlow entry point. |
| 6723 | // |
| 6724 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6725 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6726 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6727 | AddSlowPath(slow_path); |
| 6728 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6729 | __ jmp(slow_path->GetEntryLabel()); |
| 6730 | __ Bind(slow_path->GetExitLabel()); |
| 6731 | } |
| 6732 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6733 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6734 | Location out, |
| 6735 | Location ref, |
| 6736 | Location obj, |
| 6737 | uint32_t offset, |
| 6738 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6739 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6740 | // Baker's read barriers shall be handled by the fast path |
| 6741 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6742 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6743 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6744 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6745 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6746 | } else if (kPoisonHeapReferences) { |
| 6747 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6748 | } |
| 6749 | } |
| 6750 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6751 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6752 | Location out, |
| 6753 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6754 | DCHECK(kEmitCompilerReadBarrier); |
| 6755 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6756 | // Insert a slow path based read barrier *after* the GC root load. |
| 6757 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6758 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6759 | // not need to do anything special for this here. |
| 6760 | SlowPathCode* slow_path = |
| 6761 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6762 | AddSlowPath(slow_path); |
| 6763 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6764 | __ jmp(slow_path->GetEntryLabel()); |
| 6765 | __ Bind(slow_path->GetExitLabel()); |
| 6766 | } |
| 6767 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6768 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6769 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6770 | LOG(FATAL) << "Unreachable"; |
| 6771 | } |
| 6772 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6773 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6774 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6775 | LOG(FATAL) << "Unreachable"; |
| 6776 | } |
| 6777 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6778 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6779 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6780 | LocationSummary* locations = |
| 6781 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6782 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6783 | locations->AddTemp(Location::RequiresRegister()); |
| 6784 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6788 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6789 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6790 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6791 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6792 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6793 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6794 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6795 | |
| 6796 | // Should we generate smaller inline compare/jumps? |
| 6797 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6798 | // Figure out the correct compare values and jump conditions. |
| 6799 | // Handle the first compare/branch as a special case because it might |
| 6800 | // jump to the default case. |
| 6801 | DCHECK_GT(num_entries, 2u); |
| 6802 | Condition first_condition; |
| 6803 | uint32_t index; |
| 6804 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6805 | if (lower_bound != 0) { |
| 6806 | first_condition = kLess; |
| 6807 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6808 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6809 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6810 | |
| 6811 | index = 1; |
| 6812 | } else { |
| 6813 | // Handle all the compare/jumps below. |
| 6814 | first_condition = kBelow; |
| 6815 | index = 0; |
| 6816 | } |
| 6817 | |
| 6818 | // Handle the rest of the compare/jumps. |
| 6819 | for (; index + 1 < num_entries; index += 2) { |
| 6820 | int32_t compare_to_value = lower_bound + index + 1; |
| 6821 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6822 | // Jump to successors[index] if value < case_value[index]. |
| 6823 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6824 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6825 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6826 | } |
| 6827 | |
| 6828 | if (index != num_entries) { |
| 6829 | // There are an odd number of entries. Handle the last one. |
| 6830 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6831 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6832 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6833 | } |
| 6834 | |
| 6835 | // And the default for any other value. |
| 6836 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6837 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6838 | } |
| 6839 | return; |
| 6840 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6841 | |
| 6842 | // Remove the bias, if needed. |
| 6843 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6844 | if (lower_bound != 0) { |
| 6845 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6846 | value_reg_out = temp_reg.AsRegister(); |
| 6847 | } |
| 6848 | CpuRegister value_reg(value_reg_out); |
| 6849 | |
| 6850 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6851 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6852 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6853 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6854 | // We are in the range of the table. |
| 6855 | // Load the address of the jump table in the constant area. |
| 6856 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6857 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6858 | // Load the (signed) offset from the jump table. |
| 6859 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6860 | |
| 6861 | // Add the offset to the address of the table base. |
| 6862 | __ addq(temp_reg, base_reg); |
| 6863 | |
| 6864 | // And jump. |
| 6865 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6866 | } |
| 6867 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6868 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6869 | if (value == 0) { |
| 6870 | __ xorl(dest, dest); |
| 6871 | } else { |
| 6872 | __ movl(dest, Immediate(value)); |
| 6873 | } |
| 6874 | } |
| 6875 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6876 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6877 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6878 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6879 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6880 | } else if (IsUint<32>(value)) { |
| 6881 | // 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] | 6882 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6883 | } else { |
| 6884 | __ movq(dest, Immediate(value)); |
| 6885 | } |
| 6886 | } |
| 6887 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6888 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6889 | if (value == 0) { |
| 6890 | __ xorps(dest, dest); |
| 6891 | } else { |
| 6892 | __ movss(dest, LiteralInt32Address(value)); |
| 6893 | } |
| 6894 | } |
| 6895 | |
| 6896 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6897 | if (value == 0) { |
| 6898 | __ xorpd(dest, dest); |
| 6899 | } else { |
| 6900 | __ movsd(dest, LiteralInt64Address(value)); |
| 6901 | } |
| 6902 | } |
| 6903 | |
| 6904 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6905 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6906 | } |
| 6907 | |
| 6908 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6909 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6910 | } |
| 6911 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6912 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6913 | if (value == 0) { |
| 6914 | __ testl(dest, dest); |
| 6915 | } else { |
| 6916 | __ cmpl(dest, Immediate(value)); |
| 6917 | } |
| 6918 | } |
| 6919 | |
| 6920 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6921 | if (IsInt<32>(value)) { |
| 6922 | if (value == 0) { |
| 6923 | __ testq(dest, dest); |
| 6924 | } else { |
| 6925 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6926 | } |
| 6927 | } else { |
| 6928 | // Value won't fit in an int. |
| 6929 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6930 | } |
| 6931 | } |
| 6932 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6933 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 6934 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6935 | GenerateIntCompare(lhs_reg, rhs); |
| 6936 | } |
| 6937 | |
| 6938 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6939 | if (rhs.IsConstant()) { |
| 6940 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6941 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6942 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6943 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6944 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6945 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6946 | } |
| 6947 | } |
| 6948 | |
| 6949 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 6950 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 6951 | if (rhs.IsConstant()) { |
| 6952 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 6953 | Compare64BitValue(lhs_reg, value); |
| 6954 | } else if (rhs.IsDoubleStackSlot()) { |
| 6955 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 6956 | } else { |
| 6957 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 6958 | } |
| 6959 | } |
| 6960 | |
| 6961 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 6962 | Location index, |
| 6963 | ScaleFactor scale, |
| 6964 | uint32_t data_offset) { |
| 6965 | return index.IsConstant() ? |
| 6966 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 6967 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 6968 | } |
| 6969 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6970 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6971 | DCHECK(dest.IsDoubleStackSlot()); |
| 6972 | if (IsInt<32>(value)) { |
| 6973 | // Can move directly as an int32 constant. |
| 6974 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6975 | Immediate(static_cast<int32_t>(value))); |
| 6976 | } else { |
| 6977 | Load64BitValue(CpuRegister(TMP), value); |
| 6978 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6979 | } |
| 6980 | } |
| 6981 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6982 | /** |
| 6983 | * Class to handle late fixup of offsets into constant area. |
| 6984 | */ |
| 6985 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6986 | public: |
| 6987 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6988 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6989 | |
| 6990 | protected: |
| 6991 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6992 | |
| 6993 | CodeGeneratorX86_64* codegen_; |
| 6994 | |
| 6995 | private: |
| 6996 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6997 | // Patch the correct offset for the instruction. We use the address of the |
| 6998 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6999 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7000 | int32_t relative_position = constant_offset - pos; |
| 7001 | |
| 7002 | // Patch in the right value. |
| 7003 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7004 | } |
| 7005 | |
| 7006 | // Location in constant area that the fixup refers to. |
| 7007 | size_t offset_into_constant_area_; |
| 7008 | }; |
| 7009 | |
| 7010 | /** |
| 7011 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7012 | * constant area. |
| 7013 | */ |
| 7014 | class JumpTableRIPFixup : public RIPFixup { |
| 7015 | public: |
| 7016 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 7017 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7018 | |
| 7019 | void CreateJumpTable() { |
| 7020 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7021 | |
| 7022 | // Ensure that the reference to the jump table has the correct offset. |
| 7023 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7024 | SetOffset(offset_in_constant_table); |
| 7025 | |
| 7026 | // Compute the offset from the start of the function to this jump table. |
| 7027 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7028 | |
| 7029 | // Populate the jump table with the correct values for the jump table. |
| 7030 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7031 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7032 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7033 | // The value that we want is the target offset - the position of the table. |
| 7034 | for (int32_t i = 0; i < num_entries; i++) { |
| 7035 | HBasicBlock* b = successors[i]; |
| 7036 | Label* l = codegen_->GetLabelOf(b); |
| 7037 | DCHECK(l->IsBound()); |
| 7038 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7039 | assembler->AppendInt32(offset_to_block); |
| 7040 | } |
| 7041 | } |
| 7042 | |
| 7043 | private: |
| 7044 | const HPackedSwitch* switch_instr_; |
| 7045 | }; |
| 7046 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7047 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7048 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7049 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7050 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7051 | // 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] | 7052 | assembler->Align(4, 0); |
| 7053 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7054 | |
| 7055 | // Populate any jump tables. |
| 7056 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7057 | jump_table->CreateJumpTable(); |
| 7058 | } |
| 7059 | |
| 7060 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7061 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7062 | } |
| 7063 | |
| 7064 | // And finish up. |
| 7065 | CodeGenerator::Finalize(allocator); |
| 7066 | } |
| 7067 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7068 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 7069 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7070 | return Address::RIP(fixup); |
| 7071 | } |
| 7072 | |
| 7073 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 7074 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7075 | return Address::RIP(fixup); |
| 7076 | } |
| 7077 | |
| 7078 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 7079 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7080 | return Address::RIP(fixup); |
| 7081 | } |
| 7082 | |
| 7083 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 7084 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7085 | return Address::RIP(fixup); |
| 7086 | } |
| 7087 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7088 | // TODO: trg as memory. |
| 7089 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 7090 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7091 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7092 | return; |
| 7093 | } |
| 7094 | |
| 7095 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7096 | |
| 7097 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7098 | if (trg.Equals(return_loc)) { |
| 7099 | return; |
| 7100 | } |
| 7101 | |
| 7102 | // Let the parallel move resolver take care of all of this. |
| 7103 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7104 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7105 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7106 | } |
| 7107 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7108 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7109 | // Create a fixup to be used to create and address the jump table. |
| 7110 | JumpTableRIPFixup* table_fixup = |
| 7111 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7112 | |
| 7113 | // We have to populate the jump tables. |
| 7114 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7115 | return Address::RIP(table_fixup); |
| 7116 | } |
| 7117 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7118 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7119 | const Address& addr_high, |
| 7120 | int64_t v, |
| 7121 | HInstruction* instruction) { |
| 7122 | if (IsInt<32>(v)) { |
| 7123 | int32_t v_32 = v; |
| 7124 | __ movq(addr_low, Immediate(v_32)); |
| 7125 | MaybeRecordImplicitNullCheck(instruction); |
| 7126 | } else { |
| 7127 | // Didn't fit in a register. Do it in pieces. |
| 7128 | int32_t low_v = Low32Bits(v); |
| 7129 | int32_t high_v = High32Bits(v); |
| 7130 | __ movl(addr_low, Immediate(low_v)); |
| 7131 | MaybeRecordImplicitNullCheck(instruction); |
| 7132 | __ movl(addr_high, Immediate(high_v)); |
| 7133 | } |
| 7134 | } |
| 7135 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7136 | #undef __ |
| 7137 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7138 | } // namespace x86_64 |
| 7139 | } // namespace art |