Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86_64.h" |
| 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 23 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 24 | #include "intrinsics.h" |
| 25 | #include "intrinsics_x86_64.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 26 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 27 | #include "mirror/class-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 28 | #include "mirror/object_reference.h" |
| 29 | #include "thread.h" |
| 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 32 | #include "utils/x86_64/assembler_x86_64.h" |
| 33 | #include "utils/x86_64/managed_register_x86_64.h" |
| 34 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 35 | namespace art { |
| 36 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 40 | namespace x86_64 { |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = RDI; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 44 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 45 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 46 | // generates less code/data with a small num_entries. |
| 47 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 48 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 49 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 50 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 51 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 52 | static constexpr int kC2ConditionMask = 0x400; |
| 53 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 54 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 55 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 56 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 58 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 60 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 62 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 63 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 65 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 66 | // Live registers will be restored in the catch block if caught. |
| 67 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 68 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 69 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 70 | instruction_, |
| 71 | instruction_->GetDexPc(), |
| 72 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 73 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 76 | bool IsFatal() const OVERRIDE { return true; } |
| 77 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 78 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 79 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 82 | }; |
| 83 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 84 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 86 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 88 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 89 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 91 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 92 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 95 | bool IsFatal() const OVERRIDE { return true; } |
| 96 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 97 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 98 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 101 | }; |
| 102 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 103 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 105 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, Primitive::Type type, bool is_div) |
| 106 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 108 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 110 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 111 | if (is_div_) { |
| 112 | __ negl(cpu_reg_); |
| 113 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 114 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 117 | } else { |
| 118 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 119 | if (is_div_) { |
| 120 | __ negq(cpu_reg_); |
| 121 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 122 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 123 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 124 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 125 | __ jmp(GetExitLabel()); |
| 126 | } |
| 127 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 128 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 129 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 130 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 131 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 132 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 133 | const bool is_div_; |
| 134 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 137 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 138 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 139 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 140 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 141 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 142 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 143 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 144 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 145 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 146 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 147 | if (successor_ == nullptr) { |
| 148 | __ jmp(GetReturnLabel()); |
| 149 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 150 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 151 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 154 | Label* GetReturnLabel() { |
| 155 | DCHECK(successor_ == nullptr); |
| 156 | return &return_label_; |
| 157 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 158 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 159 | HBasicBlock* GetSuccessor() const { |
| 160 | return successor_; |
| 161 | } |
| 162 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 163 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 164 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 165 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 166 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 167 | Label return_label_; |
| 168 | |
| 169 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 170 | }; |
| 171 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 172 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 173 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 174 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 175 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 176 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 177 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 178 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 179 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 181 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 182 | // Live registers will be restored in the catch block if caught. |
| 183 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 184 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 185 | // Are we using an array length from memory? |
| 186 | HInstruction* array_length = instruction_->InputAt(1); |
| 187 | Location length_loc = locations->InAt(1); |
| 188 | InvokeRuntimeCallingConvention calling_convention; |
| 189 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 190 | // Load the array length into our temporary. |
| 191 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 192 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 193 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 194 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 195 | // Check for conflicts with index. |
| 196 | if (length_loc.Equals(locations->InAt(0))) { |
| 197 | // We know we aren't using parameter 2. |
| 198 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 199 | } |
| 200 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame^] | 201 | if (mirror::kUseStringCompression) { |
| 202 | __ andl(length_loc.AsRegister<CpuRegister>(), Immediate(INT32_MAX)); |
| 203 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 204 | } |
| 205 | |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 206 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 207 | // move resolver. |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 208 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 209 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 210 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 211 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 212 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 213 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 214 | Primitive::kPrimInt); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 215 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 216 | ? kQuickThrowStringBounds |
| 217 | : kQuickThrowArrayBounds; |
| 218 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 219 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 220 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 221 | } |
| 222 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 223 | bool IsFatal() const OVERRIDE { return true; } |
| 224 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 225 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 226 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 227 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 228 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 229 | }; |
| 230 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 231 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 232 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 233 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 234 | HInstruction* at, |
| 235 | uint32_t dex_pc, |
| 236 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 237 | : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 238 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 239 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 240 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 241 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 242 | LocationSummary* locations = at_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 243 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 244 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 245 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 246 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 247 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 248 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 249 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 250 | x86_64_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage : kQuickInitializeType, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 251 | at_, |
| 252 | dex_pc_, |
| 253 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 254 | if (do_clinit_) { |
| 255 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 256 | } else { |
| 257 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 258 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 259 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 260 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 261 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 262 | if (out.IsValid()) { |
| 263 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 264 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 267 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 268 | __ jmp(GetExitLabel()); |
| 269 | } |
| 270 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 271 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 272 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 273 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 274 | // The class this slow path will load. |
| 275 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 276 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 277 | // The instruction where this slow path is happening. |
| 278 | // (Might be the load class or an initialization check). |
| 279 | HInstruction* const at_; |
| 280 | |
| 281 | // The dex PC of `at_`. |
| 282 | const uint32_t dex_pc_; |
| 283 | |
| 284 | // Whether to initialize the class. |
| 285 | const bool do_clinit_; |
| 286 | |
| 287 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 288 | }; |
| 289 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 290 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 291 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 292 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 293 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 294 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 295 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 296 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 297 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 298 | : locations->Out(); |
| 299 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 300 | DCHECK(instruction_->IsCheckCast() |
| 301 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 302 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 303 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 304 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 305 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 306 | if (!is_fatal_) { |
| 307 | SaveLiveRegisters(codegen, locations); |
| 308 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 309 | |
| 310 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 311 | // move resolver. |
| 312 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 313 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 314 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 315 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 316 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 317 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 318 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 319 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 320 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 321 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 322 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 323 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 324 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 325 | } else { |
| 326 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 327 | x86_64_codegen->InvokeRuntime(kQuickCheckCast, instruction_, dex_pc, this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 328 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 329 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 330 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 331 | if (!is_fatal_) { |
| 332 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 333 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 334 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 335 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 336 | RestoreLiveRegisters(codegen, locations); |
| 337 | __ jmp(GetExitLabel()); |
| 338 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 341 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 342 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 343 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 344 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 345 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 346 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 347 | |
| 348 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 349 | }; |
| 350 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 351 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 352 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 353 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 354 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 355 | |
| 356 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 357 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 358 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 359 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 360 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 363 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 364 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 365 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 366 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 367 | }; |
| 368 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 369 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 370 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 371 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 372 | |
| 373 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 374 | LocationSummary* locations = instruction_->GetLocations(); |
| 375 | __ Bind(GetEntryLabel()); |
| 376 | SaveLiveRegisters(codegen, locations); |
| 377 | |
| 378 | InvokeRuntimeCallingConvention calling_convention; |
| 379 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 380 | parallel_move.AddMove( |
| 381 | locations->InAt(0), |
| 382 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 383 | Primitive::kPrimNot, |
| 384 | nullptr); |
| 385 | parallel_move.AddMove( |
| 386 | locations->InAt(1), |
| 387 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 388 | Primitive::kPrimInt, |
| 389 | nullptr); |
| 390 | parallel_move.AddMove( |
| 391 | locations->InAt(2), |
| 392 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 393 | Primitive::kPrimNot, |
| 394 | nullptr); |
| 395 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 396 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 397 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 398 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 399 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 400 | RestoreLiveRegisters(codegen, locations); |
| 401 | __ jmp(GetExitLabel()); |
| 402 | } |
| 403 | |
| 404 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 405 | |
| 406 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 407 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 408 | }; |
| 409 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 410 | // Slow path marking an object during a read barrier. |
| 411 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 412 | public: |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 413 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, Location obj, bool unpoison) |
| 414 | : SlowPathCode(instruction), obj_(obj), unpoison_(unpoison) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 415 | DCHECK(kEmitCompilerReadBarrier); |
| 416 | } |
| 417 | |
| 418 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 419 | |
| 420 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 421 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 422 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 423 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 424 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 425 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 426 | instruction_->IsStaticFieldGet() || |
| 427 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 428 | instruction_->IsArraySet() || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 429 | instruction_->IsLoadClass() || |
| 430 | instruction_->IsLoadString() || |
| 431 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 432 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 433 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 434 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 435 | << "Unexpected instruction in read barrier marking slow path: " |
| 436 | << instruction_->DebugName(); |
| 437 | |
| 438 | __ Bind(GetEntryLabel()); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 439 | if (unpoison_) { |
| 440 | // Object* ref = ref_addr->AsMirrorPtr() |
| 441 | __ MaybeUnpoisonHeapReference(obj_.AsRegister<CpuRegister>()); |
| 442 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 443 | // No need to save live registers; it's taken care of by the |
| 444 | // entrypoint. Also, there is no need to update the stack mask, |
| 445 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 446 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 447 | DCHECK_NE(reg, RSP); |
| 448 | DCHECK(0 <= reg && reg < kNumberOfCpuRegisters) << reg; |
| 449 | // "Compact" slow path, saving two moves. |
| 450 | // |
| 451 | // Instead of using the standard runtime calling convention (input |
| 452 | // and output in R0): |
| 453 | // |
| 454 | // RDI <- obj |
| 455 | // RAX <- ReadBarrierMark(RDI) |
| 456 | // obj <- RAX |
| 457 | // |
| 458 | // we just use rX (the register holding `obj`) as input and output |
| 459 | // of a dedicated entrypoint: |
| 460 | // |
| 461 | // rX <- ReadBarrierMarkRegX(rX) |
| 462 | // |
| 463 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 464 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 465 | // This runtime call does not require a stack map. |
| 466 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 467 | __ jmp(GetExitLabel()); |
| 468 | } |
| 469 | |
| 470 | private: |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 471 | const Location obj_; |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 472 | const bool unpoison_; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 473 | |
| 474 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 475 | }; |
| 476 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 477 | // Slow path generating a read barrier for a heap reference. |
| 478 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 479 | public: |
| 480 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 481 | Location out, |
| 482 | Location ref, |
| 483 | Location obj, |
| 484 | uint32_t offset, |
| 485 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 486 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 487 | out_(out), |
| 488 | ref_(ref), |
| 489 | obj_(obj), |
| 490 | offset_(offset), |
| 491 | index_(index) { |
| 492 | DCHECK(kEmitCompilerReadBarrier); |
| 493 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 494 | // object has been overwritten by (or after) the heap object |
| 495 | // reference load to be instrumented, e.g.: |
| 496 | // |
| 497 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 498 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 499 | // |
| 500 | // In that case, we have lost the information about the original |
| 501 | // object, and the emitted read barrier cannot work properly. |
| 502 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 503 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 504 | } |
| 505 | |
| 506 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 507 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 508 | LocationSummary* locations = instruction_->GetLocations(); |
| 509 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 510 | DCHECK(locations->CanCall()); |
| 511 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 512 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 513 | instruction_->IsStaticFieldGet() || |
| 514 | instruction_->IsArrayGet() || |
| 515 | instruction_->IsInstanceOf() || |
| 516 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 517 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 518 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 519 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 520 | |
| 521 | __ Bind(GetEntryLabel()); |
| 522 | SaveLiveRegisters(codegen, locations); |
| 523 | |
| 524 | // We may have to change the index's value, but as `index_` is a |
| 525 | // constant member (like other "inputs" of this slow path), |
| 526 | // introduce a copy of it, `index`. |
| 527 | Location index = index_; |
| 528 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 529 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 530 | if (instruction_->IsArrayGet()) { |
| 531 | // Compute real offset and store it in index_. |
| 532 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 533 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 534 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 535 | // We are about to change the value of `index_reg` (see the |
| 536 | // calls to art::x86_64::X86_64Assembler::shll and |
| 537 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 538 | // has not been saved by the previous call to |
| 539 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 540 | // callee-save register -- |
| 541 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 542 | // callee-save registers, as it has been designed with the |
| 543 | // assumption that callee-save registers are supposed to be |
| 544 | // handled by the called function. So, as a callee-save |
| 545 | // register, `index_reg` _would_ eventually be saved onto |
| 546 | // the stack, but it would be too late: we would have |
| 547 | // changed its value earlier. Therefore, we manually save |
| 548 | // it here into another freely available register, |
| 549 | // `free_reg`, chosen of course among the caller-save |
| 550 | // registers (as a callee-save `free_reg` register would |
| 551 | // exhibit the same problem). |
| 552 | // |
| 553 | // Note we could have requested a temporary register from |
| 554 | // the register allocator instead; but we prefer not to, as |
| 555 | // this is a slow path, and we know we can find a |
| 556 | // caller-save register that is available. |
| 557 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 558 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 559 | index_reg = free_reg; |
| 560 | index = Location::RegisterLocation(index_reg); |
| 561 | } else { |
| 562 | // The initial register stored in `index_` has already been |
| 563 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 564 | // (as it is not a callee-save register), so we can freely |
| 565 | // use it. |
| 566 | } |
| 567 | // Shifting the index value contained in `index_reg` by the |
| 568 | // scale factor (2) cannot overflow in practice, as the |
| 569 | // runtime is unable to allocate object arrays with a size |
| 570 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 571 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 572 | static_assert( |
| 573 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 574 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 575 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 576 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 577 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 578 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 579 | // (as in the case of ArrayGet), as it is actually an offset |
| 580 | // to an object field within an object. |
| 581 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 582 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 583 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 584 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 585 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 586 | DCHECK_EQ(offset_, 0U); |
| 587 | DCHECK(index_.IsRegister()); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | // We're moving two or three locations to locations that could |
| 592 | // overlap, so we need a parallel move resolver. |
| 593 | InvokeRuntimeCallingConvention calling_convention; |
| 594 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 595 | parallel_move.AddMove(ref_, |
| 596 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 597 | Primitive::kPrimNot, |
| 598 | nullptr); |
| 599 | parallel_move.AddMove(obj_, |
| 600 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 601 | Primitive::kPrimNot, |
| 602 | nullptr); |
| 603 | if (index.IsValid()) { |
| 604 | parallel_move.AddMove(index, |
| 605 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 606 | Primitive::kPrimInt, |
| 607 | nullptr); |
| 608 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 609 | } else { |
| 610 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 611 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 612 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 613 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 614 | instruction_, |
| 615 | instruction_->GetDexPc(), |
| 616 | this); |
| 617 | CheckEntrypointTypes< |
| 618 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 619 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 620 | |
| 621 | RestoreLiveRegisters(codegen, locations); |
| 622 | __ jmp(GetExitLabel()); |
| 623 | } |
| 624 | |
| 625 | const char* GetDescription() const OVERRIDE { |
| 626 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 627 | } |
| 628 | |
| 629 | private: |
| 630 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 631 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 632 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 633 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 634 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 635 | return static_cast<CpuRegister>(i); |
| 636 | } |
| 637 | } |
| 638 | // We shall never fail to find a free caller-save register, as |
| 639 | // there are more than two core caller-save registers on x86-64 |
| 640 | // (meaning it is possible to find one which is different from |
| 641 | // `ref` and `obj`). |
| 642 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 643 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 644 | UNREACHABLE(); |
| 645 | } |
| 646 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 647 | const Location out_; |
| 648 | const Location ref_; |
| 649 | const Location obj_; |
| 650 | const uint32_t offset_; |
| 651 | // An additional location containing an index to an array. |
| 652 | // Only used for HArrayGet and the UnsafeGetObject & |
| 653 | // UnsafeGetObjectVolatile intrinsics. |
| 654 | const Location index_; |
| 655 | |
| 656 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 657 | }; |
| 658 | |
| 659 | // Slow path generating a read barrier for a GC root. |
| 660 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 661 | public: |
| 662 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 663 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 664 | DCHECK(kEmitCompilerReadBarrier); |
| 665 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 666 | |
| 667 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 668 | LocationSummary* locations = instruction_->GetLocations(); |
| 669 | DCHECK(locations->CanCall()); |
| 670 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 671 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 672 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 673 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 674 | |
| 675 | __ Bind(GetEntryLabel()); |
| 676 | SaveLiveRegisters(codegen, locations); |
| 677 | |
| 678 | InvokeRuntimeCallingConvention calling_convention; |
| 679 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 680 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 681 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 682 | instruction_, |
| 683 | instruction_->GetDexPc(), |
| 684 | this); |
| 685 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 686 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 687 | |
| 688 | RestoreLiveRegisters(codegen, locations); |
| 689 | __ jmp(GetExitLabel()); |
| 690 | } |
| 691 | |
| 692 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 693 | |
| 694 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 695 | const Location out_; |
| 696 | const Location root_; |
| 697 | |
| 698 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 699 | }; |
| 700 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 701 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 702 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 703 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 704 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 705 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 706 | switch (cond) { |
| 707 | case kCondEQ: return kEqual; |
| 708 | case kCondNE: return kNotEqual; |
| 709 | case kCondLT: return kLess; |
| 710 | case kCondLE: return kLessEqual; |
| 711 | case kCondGT: return kGreater; |
| 712 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 713 | case kCondB: return kBelow; |
| 714 | case kCondBE: return kBelowEqual; |
| 715 | case kCondA: return kAbove; |
| 716 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 717 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 718 | LOG(FATAL) << "Unreachable"; |
| 719 | UNREACHABLE(); |
| 720 | } |
| 721 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 722 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 723 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 724 | switch (cond) { |
| 725 | case kCondEQ: return kEqual; |
| 726 | case kCondNE: return kNotEqual; |
| 727 | case kCondLT: return kBelow; |
| 728 | case kCondLE: return kBelowEqual; |
| 729 | case kCondGT: return kAbove; |
| 730 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 731 | default: break; // should not happen |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 732 | }; |
| 733 | LOG(FATAL) << "Unreachable"; |
| 734 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 737 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 738 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 739 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 740 | switch (desired_dispatch_info.code_ptr_location) { |
| 741 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 742 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 743 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 744 | return HInvokeStaticOrDirect::DispatchInfo { |
| 745 | desired_dispatch_info.method_load_kind, |
| 746 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 747 | desired_dispatch_info.method_load_data, |
| 748 | 0u |
| 749 | }; |
| 750 | default: |
| 751 | return desired_dispatch_info; |
| 752 | } |
| 753 | } |
| 754 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 755 | Location CodeGeneratorX86_64::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 756 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 757 | // All registers are assumed to be correctly set up. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 758 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 759 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 760 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 761 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 762 | uint32_t offset = |
| 763 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 764 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 765 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 766 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 767 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 768 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 769 | break; |
| 770 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 771 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 772 | break; |
| 773 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 774 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 775 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 776 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 777 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 778 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 779 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 780 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 781 | // Bind a new fixup label at the end of the "movl" insn. |
| 782 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 783 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFile(), offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 784 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 785 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 786 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 787 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 788 | Register method_reg; |
| 789 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 790 | if (current_method.IsRegister()) { |
| 791 | method_reg = current_method.AsRegister<Register>(); |
| 792 | } else { |
| 793 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 794 | DCHECK(!current_method.IsValid()); |
| 795 | method_reg = reg.AsRegister(); |
| 796 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 797 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 798 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 799 | __ movq(reg, |
| 800 | Address(CpuRegister(method_reg), |
| 801 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 802 | // temp = temp[index_in_cache]; |
| 803 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 804 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 805 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 806 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 807 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 808 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 809 | return callee_method; |
| 810 | } |
| 811 | |
| 812 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 813 | Location temp) { |
| 814 | // All registers are assumed to be correctly set up. |
| 815 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 816 | |
| 817 | switch (invoke->GetCodePtrLocation()) { |
| 818 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 819 | __ call(&frame_entry_label_); |
| 820 | break; |
| 821 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 822 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 823 | Label* label = &relative_call_patches_.back().label; |
| 824 | __ call(label); // Bind to the patch label, override at link time. |
| 825 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 826 | break; |
| 827 | } |
| 828 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 829 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 830 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 831 | LOG(FATAL) << "Unsupported"; |
| 832 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 833 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 834 | // (callee_method + offset_of_quick_compiled_code)() |
| 835 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 836 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 837 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 838 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 839 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 840 | |
| 841 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 842 | } |
| 843 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 844 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 845 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 846 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 847 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 848 | |
| 849 | // Use the calling convention instead of the location of the receiver, as |
| 850 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 851 | // slow path, the arguments have been moved to the right place, so here we are |
| 852 | // guaranteed that the receiver is the first register of the calling convention. |
| 853 | InvokeDexCallingConvention calling_convention; |
| 854 | Register receiver = calling_convention.GetRegisterAt(0); |
| 855 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 856 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 857 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 858 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 859 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 860 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 861 | // emit a read barrier for the previous class reference load. |
| 862 | // However this is not required in practice, as this is an |
| 863 | // intermediate/temporary reference and because the current |
| 864 | // concurrent copying collector keeps the from-space memory |
| 865 | // intact/accessible until the end of the marking phase (the |
| 866 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 867 | __ MaybeUnpoisonHeapReference(temp); |
| 868 | // temp = temp->GetMethodAt(method_offset); |
| 869 | __ movq(temp, Address(temp, method_offset)); |
| 870 | // call temp->GetEntryPoint(); |
| 871 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 872 | kX86_64PointerSize).SizeValue())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 875 | void CodeGeneratorX86_64::RecordSimplePatch() { |
| 876 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 877 | simple_patches_.emplace_back(); |
| 878 | __ Bind(&simple_patches_.back()); |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | void CodeGeneratorX86_64::RecordStringPatch(HLoadString* load_string) { |
| 883 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 884 | __ Bind(&string_patches_.back().label); |
| 885 | } |
| 886 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 887 | void CodeGeneratorX86_64::RecordTypePatch(HLoadClass* load_class) { |
| 888 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 889 | __ Bind(&type_patches_.back().label); |
| 890 | } |
| 891 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 892 | Label* CodeGeneratorX86_64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 893 | uint32_t element_offset) { |
| 894 | // Add a patch entry and return the label. |
| 895 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 896 | return &pc_relative_dex_cache_patches_.back().label; |
| 897 | } |
| 898 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 899 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 900 | DCHECK(linker_patches->empty()); |
| 901 | size_t size = |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 902 | method_patches_.size() + |
| 903 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 904 | pc_relative_dex_cache_patches_.size() + |
| 905 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 906 | string_patches_.size() + |
| 907 | type_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 908 | linker_patches->reserve(size); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 909 | // The label points to the end of the "movl" insn but the literal offset for method |
| 910 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 911 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 912 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 913 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 914 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 915 | info.target_method.dex_file, |
| 916 | info.target_method.dex_method_index)); |
| 917 | } |
| 918 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 919 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 920 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 921 | info.target_method.dex_file, |
| 922 | info.target_method.dex_method_index)); |
| 923 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 924 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 925 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 926 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 927 | &info.target_dex_file, |
| 928 | info.label.Position(), |
| 929 | info.element_offset)); |
| 930 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 931 | for (const Label& label : simple_patches_) { |
| 932 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 933 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 934 | } |
| 935 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 936 | // These are always PC-relative, see GetSupportedLoadStringKind(). |
| 937 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 938 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 939 | &info.dex_file, |
| 940 | info.label.Position(), |
| 941 | info.string_index)); |
| 942 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 943 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 944 | // These are always PC-relative, see GetSupportedLoadClassKind(). |
| 945 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 946 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(literal_offset, |
| 947 | &info.dex_file, |
| 948 | info.label.Position(), |
| 949 | info.type_index)); |
| 950 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 953 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 954 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 958 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 959 | } |
| 960 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 961 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 962 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 963 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 964 | } |
| 965 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 966 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 967 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 968 | return kX86_64WordSize; |
| 969 | } |
| 970 | |
| 971 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 972 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 973 | return kX86_64WordSize; |
| 974 | } |
| 975 | |
| 976 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 977 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 978 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 979 | } |
| 980 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 981 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 982 | HInstruction* instruction, |
| 983 | uint32_t dex_pc, |
| 984 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 985 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 986 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 987 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 988 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 989 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 990 | } |
| 991 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 992 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 993 | HInstruction* instruction, |
| 994 | SlowPathCode* slow_path) { |
| 995 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 996 | GenerateInvokeRuntime(entry_point_offset); |
| 997 | } |
| 998 | |
| 999 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1000 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
| 1001 | } |
| 1002 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1003 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1004 | // Use a fake return address register to mimic Quick. |
| 1005 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1006 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1007 | const X86_64InstructionSetFeatures& isa_features, |
| 1008 | const CompilerOptions& compiler_options, |
| 1009 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1010 | : CodeGenerator(graph, |
| 1011 | kNumberOfCpuRegisters, |
| 1012 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1013 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1014 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1015 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1016 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1017 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1018 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1019 | compiler_options, |
| 1020 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1021 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1022 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1023 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1024 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1025 | assembler_(graph->GetArena()), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1026 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1027 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1028 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1029 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1030 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1031 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1032 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1033 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 1034 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1035 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1036 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1037 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1038 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1039 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1040 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1041 | assembler_(codegen->GetAssembler()), |
| 1042 | codegen_(codegen) {} |
| 1043 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1044 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1045 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1046 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1047 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1048 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1049 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1050 | } |
| 1051 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1052 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1053 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1054 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1055 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1056 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1057 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1060 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1061 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1062 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1063 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1064 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1065 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1066 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1067 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1068 | __ testq(CpuRegister(RAX), Address( |
| 1069 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1070 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1071 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1072 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1073 | if (HasEmptyFrame()) { |
| 1074 | return; |
| 1075 | } |
| 1076 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1077 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1078 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1079 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1080 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1081 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1082 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1083 | } |
| 1084 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1085 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1086 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1087 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1088 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1089 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1090 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1091 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1092 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1093 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1094 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1095 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1096 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1097 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1100 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1101 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1105 | __ cfi().RememberState(); |
| 1106 | if (!HasEmptyFrame()) { |
| 1107 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1108 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1109 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1110 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1111 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1112 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1113 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1118 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1119 | __ cfi().AdjustCFAOffset(-adjust); |
| 1120 | |
| 1121 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1122 | Register reg = kCoreCalleeSaves[i]; |
| 1123 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1124 | __ popq(CpuRegister(reg)); |
| 1125 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1126 | __ cfi().Restore(DWARFReg(reg)); |
| 1127 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1128 | } |
| 1129 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1130 | __ ret(); |
| 1131 | __ cfi().RestoreState(); |
| 1132 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1133 | } |
| 1134 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1135 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1136 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1137 | } |
| 1138 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1139 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1140 | if (source.Equals(destination)) { |
| 1141 | return; |
| 1142 | } |
| 1143 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1144 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1145 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1146 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1147 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1148 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1149 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1150 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1151 | } else if (source.IsConstant()) { |
| 1152 | HConstant* constant = source.GetConstant(); |
| 1153 | if (constant->IsLongConstant()) { |
| 1154 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1155 | } else { |
| 1156 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1157 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1158 | } else { |
| 1159 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1160 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1161 | } |
| 1162 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1163 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1164 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1165 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1166 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1167 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1168 | } else if (source.IsConstant()) { |
| 1169 | HConstant* constant = source.GetConstant(); |
| 1170 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1171 | if (constant->IsFloatConstant()) { |
| 1172 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1173 | } else { |
| 1174 | Load64BitValue(dest, value); |
| 1175 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1176 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1177 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1178 | } else { |
| 1179 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1180 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1181 | } |
| 1182 | } else if (destination.IsStackSlot()) { |
| 1183 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1184 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1185 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1186 | } else if (source.IsFpuRegister()) { |
| 1187 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1188 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1189 | } else if (source.IsConstant()) { |
| 1190 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1191 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1192 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1193 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1194 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1195 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1196 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1197 | } |
| 1198 | } else { |
| 1199 | DCHECK(destination.IsDoubleStackSlot()); |
| 1200 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1201 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1202 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1203 | } else if (source.IsFpuRegister()) { |
| 1204 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1205 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1206 | } else if (source.IsConstant()) { |
| 1207 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1208 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1209 | int64_t value = GetInt64ValueOf(constant); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1210 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1211 | } else { |
| 1212 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1213 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1214 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1219 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1220 | DCHECK(location.IsRegister()); |
| 1221 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1222 | } |
| 1223 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1224 | void CodeGeneratorX86_64::MoveLocation( |
| 1225 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1226 | Move(dst, src); |
| 1227 | } |
| 1228 | |
| 1229 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1230 | if (location.IsRegister()) { |
| 1231 | locations->AddTemp(location); |
| 1232 | } else { |
| 1233 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1234 | } |
| 1235 | } |
| 1236 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1237 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1238 | DCHECK(!successor->IsExitBlock()); |
| 1239 | |
| 1240 | HBasicBlock* block = got->GetBlock(); |
| 1241 | HInstruction* previous = got->GetPrevious(); |
| 1242 | |
| 1243 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1244 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1245 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1246 | return; |
| 1247 | } |
| 1248 | |
| 1249 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1250 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1251 | } |
| 1252 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1253 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1254 | } |
| 1255 | } |
| 1256 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1257 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1258 | got->SetLocations(nullptr); |
| 1259 | } |
| 1260 | |
| 1261 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1262 | HandleGoto(got, got->GetSuccessor()); |
| 1263 | } |
| 1264 | |
| 1265 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1266 | try_boundary->SetLocations(nullptr); |
| 1267 | } |
| 1268 | |
| 1269 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1270 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1271 | if (!successor->IsExitBlock()) { |
| 1272 | HandleGoto(try_boundary, successor); |
| 1273 | } |
| 1274 | } |
| 1275 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1276 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1277 | exit->SetLocations(nullptr); |
| 1278 | } |
| 1279 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1280 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1281 | } |
| 1282 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1283 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1284 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1285 | LabelType* true_label, |
| 1286 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1287 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1288 | __ j(kUnordered, true_label); |
| 1289 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1290 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1291 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1292 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1293 | } |
| 1294 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1295 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1296 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1297 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1298 | Location left = locations->InAt(0); |
| 1299 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1300 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1301 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1302 | case Primitive::kPrimBoolean: |
| 1303 | case Primitive::kPrimByte: |
| 1304 | case Primitive::kPrimChar: |
| 1305 | case Primitive::kPrimShort: |
| 1306 | case Primitive::kPrimInt: |
| 1307 | case Primitive::kPrimNot: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1308 | codegen_->GenerateIntCompare(left, right); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1309 | break; |
| 1310 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1311 | case Primitive::kPrimLong: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1312 | codegen_->GenerateLongCompare(left, right); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1313 | break; |
| 1314 | } |
| 1315 | case Primitive::kPrimFloat: { |
| 1316 | if (right.IsFpuRegister()) { |
| 1317 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1318 | } else if (right.IsConstant()) { |
| 1319 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1320 | codegen_->LiteralFloatAddress( |
| 1321 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1322 | } else { |
| 1323 | DCHECK(right.IsStackSlot()); |
| 1324 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1325 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1326 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1327 | break; |
| 1328 | } |
| 1329 | case Primitive::kPrimDouble: { |
| 1330 | if (right.IsFpuRegister()) { |
| 1331 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1332 | } else if (right.IsConstant()) { |
| 1333 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1334 | codegen_->LiteralDoubleAddress( |
| 1335 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1336 | } else { |
| 1337 | DCHECK(right.IsDoubleStackSlot()); |
| 1338 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1339 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1340 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1341 | break; |
| 1342 | } |
| 1343 | default: |
| 1344 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | template<class LabelType> |
| 1349 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1350 | LabelType* true_target_in, |
| 1351 | LabelType* false_target_in) { |
| 1352 | // Generated branching requires both targets to be explicit. If either of the |
| 1353 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1354 | LabelType fallthrough_target; |
| 1355 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1356 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1357 | |
| 1358 | // Generate the comparison to set the CC. |
| 1359 | GenerateCompareTest(condition); |
| 1360 | |
| 1361 | // Now generate the correct jump(s). |
| 1362 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1363 | switch (type) { |
| 1364 | case Primitive::kPrimLong: { |
| 1365 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1366 | break; |
| 1367 | } |
| 1368 | case Primitive::kPrimFloat: { |
| 1369 | GenerateFPJumps(condition, true_target, false_target); |
| 1370 | break; |
| 1371 | } |
| 1372 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1373 | GenerateFPJumps(condition, true_target, false_target); |
| 1374 | break; |
| 1375 | } |
| 1376 | default: |
| 1377 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1378 | } |
| 1379 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1380 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1381 | __ jmp(false_target); |
| 1382 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1383 | |
| 1384 | if (fallthrough_target.IsLinked()) { |
| 1385 | __ Bind(&fallthrough_target); |
| 1386 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1387 | } |
| 1388 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1389 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1390 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1391 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1392 | // conditions if they are materialized due to the complex branching. |
| 1393 | return cond->IsCondition() && |
| 1394 | cond->GetNext() == branch && |
| 1395 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1396 | } |
| 1397 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1398 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1399 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1400 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1401 | LabelType* true_target, |
| 1402 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1403 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1404 | |
| 1405 | if (true_target == nullptr && false_target == nullptr) { |
| 1406 | // Nothing to do. The code always falls through. |
| 1407 | return; |
| 1408 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1409 | // Constant condition, statically compared against "true" (integer value 1). |
| 1410 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1411 | if (true_target != nullptr) { |
| 1412 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1413 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1414 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1415 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1416 | if (false_target != nullptr) { |
| 1417 | __ jmp(false_target); |
| 1418 | } |
| 1419 | } |
| 1420 | return; |
| 1421 | } |
| 1422 | |
| 1423 | // The following code generates these patterns: |
| 1424 | // (1) true_target == nullptr && false_target != nullptr |
| 1425 | // - opposite condition true => branch to false_target |
| 1426 | // (2) true_target != nullptr && false_target == nullptr |
| 1427 | // - condition true => branch to true_target |
| 1428 | // (3) true_target != nullptr && false_target != nullptr |
| 1429 | // - condition true => branch to true_target |
| 1430 | // - branch to false_target |
| 1431 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1432 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1433 | if (true_target == nullptr) { |
| 1434 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1435 | } else { |
| 1436 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1437 | } |
| 1438 | } else { |
| 1439 | // Materialized condition, compare against 0. |
| 1440 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1441 | if (lhs.IsRegister()) { |
| 1442 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1443 | } else { |
| 1444 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1445 | } |
| 1446 | if (true_target == nullptr) { |
| 1447 | __ j(kEqual, false_target); |
| 1448 | } else { |
| 1449 | __ j(kNotEqual, true_target); |
| 1450 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1451 | } |
| 1452 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1453 | // Condition has not been materialized, use its inputs as the |
| 1454 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1455 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1456 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1457 | // If this is a long or FP comparison that has been folded into |
| 1458 | // the HCondition, generate the comparison directly. |
| 1459 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1460 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1461 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1462 | return; |
| 1463 | } |
| 1464 | |
| 1465 | Location lhs = condition->GetLocations()->InAt(0); |
| 1466 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1467 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1468 | if (true_target == nullptr) { |
| 1469 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1470 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1471 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1472 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1473 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1474 | |
| 1475 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1476 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1477 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1478 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1479 | } |
| 1480 | } |
| 1481 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1482 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1483 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1484 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1485 | locations->SetInAt(0, Location::Any()); |
| 1486 | } |
| 1487 | } |
| 1488 | |
| 1489 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1490 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1491 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1492 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1493 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1494 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1495 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1496 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1500 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1501 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1502 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1503 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1504 | locations->SetInAt(0, Location::Any()); |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1509 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1510 | GenerateTestAndBranch<Label>(deoptimize, |
| 1511 | /* condition_input_index */ 0, |
| 1512 | slow_path->GetEntryLabel(), |
| 1513 | /* false_target */ nullptr); |
| 1514 | } |
| 1515 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1516 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1517 | // There are no conditional move instructions for XMMs. |
| 1518 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1519 | return false; |
| 1520 | } |
| 1521 | |
| 1522 | // A FP condition doesn't generate the single CC that we need. |
| 1523 | HInstruction* condition = select->GetCondition(); |
| 1524 | if (condition->IsCondition() && |
| 1525 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1526 | return false; |
| 1527 | } |
| 1528 | |
| 1529 | // We can generate a CMOV for this Select. |
| 1530 | return true; |
| 1531 | } |
| 1532 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1533 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1534 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1535 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1536 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1537 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1538 | } else { |
| 1539 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1540 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1541 | if (select->InputAt(1)->IsConstant()) { |
| 1542 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1543 | } else { |
| 1544 | locations->SetInAt(1, Location::Any()); |
| 1545 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1546 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1547 | locations->SetInAt(1, Location::Any()); |
| 1548 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1549 | } |
| 1550 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1551 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1552 | } |
| 1553 | locations->SetOut(Location::SameAsFirstInput()); |
| 1554 | } |
| 1555 | |
| 1556 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1557 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1558 | if (SelectCanUseCMOV(select)) { |
| 1559 | // If both the condition and the source types are integer, we can generate |
| 1560 | // a CMOV to implement Select. |
| 1561 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1562 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1563 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1564 | |
| 1565 | HInstruction* select_condition = select->GetCondition(); |
| 1566 | Condition cond = kNotEqual; |
| 1567 | |
| 1568 | // Figure out how to test the 'condition'. |
| 1569 | if (select_condition->IsCondition()) { |
| 1570 | HCondition* condition = select_condition->AsCondition(); |
| 1571 | if (!condition->IsEmittedAtUseSite()) { |
| 1572 | // This was a previously materialized condition. |
| 1573 | // Can we use the existing condition code? |
| 1574 | if (AreEflagsSetFrom(condition, select)) { |
| 1575 | // Materialization was the previous instruction. Condition codes are right. |
| 1576 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1577 | } else { |
| 1578 | // No, we have to recreate the condition code. |
| 1579 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1580 | __ testl(cond_reg, cond_reg); |
| 1581 | } |
| 1582 | } else { |
| 1583 | GenerateCompareTest(condition); |
| 1584 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1585 | } |
| 1586 | } else { |
| 1587 | // Must be a boolean condition, which needs to be compared to 0. |
| 1588 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1589 | __ testl(cond_reg, cond_reg); |
| 1590 | } |
| 1591 | |
| 1592 | // If the condition is true, overwrite the output, which already contains false. |
| 1593 | // Generate the correct sized CMOV. |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1594 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1595 | if (value_true_loc.IsRegister()) { |
| 1596 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1597 | } else { |
| 1598 | __ cmov(cond, |
| 1599 | value_false, |
| 1600 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1601 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1602 | } else { |
| 1603 | NearLabel false_target; |
| 1604 | GenerateTestAndBranch<NearLabel>(select, |
| 1605 | /* condition_input_index */ 2, |
| 1606 | /* true_target */ nullptr, |
| 1607 | &false_target); |
| 1608 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1609 | __ Bind(&false_target); |
| 1610 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1613 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1614 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1615 | } |
| 1616 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1617 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1618 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | void CodeGeneratorX86_64::GenerateNop() { |
| 1622 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1625 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1626 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1627 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1628 | // Handle the long/FP comparisons made in instruction simplification. |
| 1629 | switch (cond->InputAt(0)->GetType()) { |
| 1630 | case Primitive::kPrimLong: |
| 1631 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1632 | locations->SetInAt(1, Location::Any()); |
| 1633 | break; |
| 1634 | case Primitive::kPrimFloat: |
| 1635 | case Primitive::kPrimDouble: |
| 1636 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1637 | locations->SetInAt(1, Location::Any()); |
| 1638 | break; |
| 1639 | default: |
| 1640 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1641 | locations->SetInAt(1, Location::Any()); |
| 1642 | break; |
| 1643 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1644 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1645 | locations->SetOut(Location::RequiresRegister()); |
| 1646 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1647 | } |
| 1648 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1649 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1650 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1651 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1652 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1653 | |
| 1654 | LocationSummary* locations = cond->GetLocations(); |
| 1655 | Location lhs = locations->InAt(0); |
| 1656 | Location rhs = locations->InAt(1); |
| 1657 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1658 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1659 | |
| 1660 | switch (cond->InputAt(0)->GetType()) { |
| 1661 | default: |
| 1662 | // Integer case. |
| 1663 | |
| 1664 | // Clear output register: setcc only sets the low byte. |
| 1665 | __ xorl(reg, reg); |
| 1666 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1667 | codegen_->GenerateIntCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1668 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1669 | return; |
| 1670 | case Primitive::kPrimLong: |
| 1671 | // Clear output register: setcc only sets the low byte. |
| 1672 | __ xorl(reg, reg); |
| 1673 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1674 | codegen_->GenerateLongCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1675 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1676 | return; |
| 1677 | case Primitive::kPrimFloat: { |
| 1678 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1679 | if (rhs.IsConstant()) { |
| 1680 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1681 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1682 | } else if (rhs.IsStackSlot()) { |
| 1683 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1684 | } else { |
| 1685 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1686 | } |
| 1687 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1688 | break; |
| 1689 | } |
| 1690 | case Primitive::kPrimDouble: { |
| 1691 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1692 | if (rhs.IsConstant()) { |
| 1693 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1694 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1695 | } else if (rhs.IsDoubleStackSlot()) { |
| 1696 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1697 | } else { |
| 1698 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1699 | } |
| 1700 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1701 | break; |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1706 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1707 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1708 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1709 | __ Bind(&false_label); |
| 1710 | __ xorl(reg, reg); |
| 1711 | __ jmp(&done_label); |
| 1712 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1713 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1714 | __ Bind(&true_label); |
| 1715 | __ movl(reg, Immediate(1)); |
| 1716 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1720 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1724 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1728 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1732 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1736 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1740 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1744 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1748 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1752 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1756 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1760 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1764 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1765 | } |
| 1766 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1767 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1768 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1772 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1776 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1780 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1784 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1788 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1792 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1796 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1799 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1800 | LocationSummary* locations = |
| 1801 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1802 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1803 | case Primitive::kPrimBoolean: |
| 1804 | case Primitive::kPrimByte: |
| 1805 | case Primitive::kPrimShort: |
| 1806 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1807 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1808 | case Primitive::kPrimLong: { |
| 1809 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1810 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1811 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1812 | break; |
| 1813 | } |
| 1814 | case Primitive::kPrimFloat: |
| 1815 | case Primitive::kPrimDouble: { |
| 1816 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1817 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1818 | locations->SetOut(Location::RequiresRegister()); |
| 1819 | break; |
| 1820 | } |
| 1821 | default: |
| 1822 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1823 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1827 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1828 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1829 | Location left = locations->InAt(0); |
| 1830 | Location right = locations->InAt(1); |
| 1831 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1832 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1833 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1834 | Condition less_cond = kLess; |
| 1835 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1836 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1837 | case Primitive::kPrimBoolean: |
| 1838 | case Primitive::kPrimByte: |
| 1839 | case Primitive::kPrimShort: |
| 1840 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1841 | case Primitive::kPrimInt: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1842 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1843 | break; |
| 1844 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1845 | case Primitive::kPrimLong: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1846 | codegen_->GenerateLongCompare(left, right); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1847 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1848 | } |
| 1849 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1850 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1851 | if (right.IsConstant()) { |
| 1852 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1853 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1854 | } else if (right.IsStackSlot()) { |
| 1855 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1856 | } else { |
| 1857 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1858 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1859 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1860 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1861 | break; |
| 1862 | } |
| 1863 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1864 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1865 | if (right.IsConstant()) { |
| 1866 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1867 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1868 | } else if (right.IsDoubleStackSlot()) { |
| 1869 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1870 | } else { |
| 1871 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1872 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1873 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1874 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1875 | break; |
| 1876 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1877 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1878 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1879 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1880 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1881 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1882 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1883 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1884 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1885 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1886 | __ movl(out, Immediate(1)); |
| 1887 | __ jmp(&done); |
| 1888 | |
| 1889 | __ Bind(&less); |
| 1890 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1891 | |
| 1892 | __ Bind(&done); |
| 1893 | } |
| 1894 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1895 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1896 | LocationSummary* locations = |
| 1897 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1898 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1899 | } |
| 1900 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1901 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1902 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1903 | } |
| 1904 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1905 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1906 | LocationSummary* locations = |
| 1907 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1908 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1909 | } |
| 1910 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1911 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1912 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1913 | } |
| 1914 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1915 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1916 | LocationSummary* locations = |
| 1917 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1918 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1919 | } |
| 1920 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1921 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1922 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1923 | } |
| 1924 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1925 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1926 | LocationSummary* locations = |
| 1927 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1928 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1929 | } |
| 1930 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1931 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1932 | // Will be generated at use site. |
| 1933 | } |
| 1934 | |
| 1935 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1936 | LocationSummary* locations = |
| 1937 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1938 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1939 | } |
| 1940 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1941 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 1942 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1943 | // Will be generated at use site. |
| 1944 | } |
| 1945 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1946 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1947 | memory_barrier->SetLocations(nullptr); |
| 1948 | } |
| 1949 | |
| 1950 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 1951 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1952 | } |
| 1953 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1954 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1955 | ret->SetLocations(nullptr); |
| 1956 | } |
| 1957 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1958 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1959 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1963 | LocationSummary* locations = |
| 1964 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1965 | switch (ret->InputAt(0)->GetType()) { |
| 1966 | case Primitive::kPrimBoolean: |
| 1967 | case Primitive::kPrimByte: |
| 1968 | case Primitive::kPrimChar: |
| 1969 | case Primitive::kPrimShort: |
| 1970 | case Primitive::kPrimInt: |
| 1971 | case Primitive::kPrimNot: |
| 1972 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1973 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1974 | break; |
| 1975 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1976 | case Primitive::kPrimFloat: |
| 1977 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1978 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1979 | break; |
| 1980 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1981 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1982 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1983 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 1987 | if (kIsDebugBuild) { |
| 1988 | switch (ret->InputAt(0)->GetType()) { |
| 1989 | case Primitive::kPrimBoolean: |
| 1990 | case Primitive::kPrimByte: |
| 1991 | case Primitive::kPrimChar: |
| 1992 | case Primitive::kPrimShort: |
| 1993 | case Primitive::kPrimInt: |
| 1994 | case Primitive::kPrimNot: |
| 1995 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1996 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1997 | break; |
| 1998 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1999 | case Primitive::kPrimFloat: |
| 2000 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2001 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2002 | XMM0); |
| 2003 | break; |
| 2004 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2005 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2006 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2007 | } |
| 2008 | } |
| 2009 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2010 | } |
| 2011 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2012 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2013 | switch (type) { |
| 2014 | case Primitive::kPrimBoolean: |
| 2015 | case Primitive::kPrimByte: |
| 2016 | case Primitive::kPrimChar: |
| 2017 | case Primitive::kPrimShort: |
| 2018 | case Primitive::kPrimInt: |
| 2019 | case Primitive::kPrimNot: |
| 2020 | case Primitive::kPrimLong: |
| 2021 | return Location::RegisterLocation(RAX); |
| 2022 | |
| 2023 | case Primitive::kPrimVoid: |
| 2024 | return Location::NoLocation(); |
| 2025 | |
| 2026 | case Primitive::kPrimDouble: |
| 2027 | case Primitive::kPrimFloat: |
| 2028 | return Location::FpuRegisterLocation(XMM0); |
| 2029 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2030 | |
| 2031 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2035 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2036 | } |
| 2037 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2038 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2039 | switch (type) { |
| 2040 | case Primitive::kPrimBoolean: |
| 2041 | case Primitive::kPrimByte: |
| 2042 | case Primitive::kPrimChar: |
| 2043 | case Primitive::kPrimShort: |
| 2044 | case Primitive::kPrimInt: |
| 2045 | case Primitive::kPrimNot: { |
| 2046 | uint32_t index = gp_index_++; |
| 2047 | stack_index_++; |
| 2048 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2049 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2050 | } else { |
| 2051 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | case Primitive::kPrimLong: { |
| 2056 | uint32_t index = gp_index_; |
| 2057 | stack_index_ += 2; |
| 2058 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2059 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2060 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2061 | } else { |
| 2062 | gp_index_ += 2; |
| 2063 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2064 | } |
| 2065 | } |
| 2066 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2067 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2068 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2069 | stack_index_++; |
| 2070 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2071 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2072 | } else { |
| 2073 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2074 | } |
| 2075 | } |
| 2076 | |
| 2077 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2078 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2079 | stack_index_ += 2; |
| 2080 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2081 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2082 | } else { |
| 2083 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2084 | } |
| 2085 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2086 | |
| 2087 | case Primitive::kPrimVoid: |
| 2088 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2089 | break; |
| 2090 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2091 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2092 | } |
| 2093 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2094 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2095 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2096 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2097 | // the method_idx. |
| 2098 | HandleInvoke(invoke); |
| 2099 | } |
| 2100 | |
| 2101 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2102 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2103 | } |
| 2104 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2105 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2106 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2107 | // art::PrepareForRegisterAllocation. |
| 2108 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2109 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2110 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2111 | if (intrinsic.TryDispatch(invoke)) { |
| 2112 | return; |
| 2113 | } |
| 2114 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2115 | HandleInvoke(invoke); |
| 2116 | } |
| 2117 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2118 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2119 | if (invoke->GetLocations()->Intrinsified()) { |
| 2120 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2121 | intrinsic.Dispatch(invoke); |
| 2122 | return true; |
| 2123 | } |
| 2124 | return false; |
| 2125 | } |
| 2126 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2127 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2128 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2129 | // art::PrepareForRegisterAllocation. |
| 2130 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2131 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2132 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2133 | return; |
| 2134 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2135 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2136 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2137 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2138 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2139 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2140 | } |
| 2141 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2142 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2143 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2144 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2145 | } |
| 2146 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2147 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2148 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2149 | if (intrinsic.TryDispatch(invoke)) { |
| 2150 | return; |
| 2151 | } |
| 2152 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2153 | HandleInvoke(invoke); |
| 2154 | } |
| 2155 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2156 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2157 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2158 | return; |
| 2159 | } |
| 2160 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2161 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2162 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2163 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2164 | } |
| 2165 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2166 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2167 | HandleInvoke(invoke); |
| 2168 | // Add the hidden argument. |
| 2169 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2170 | } |
| 2171 | |
| 2172 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2173 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2174 | LocationSummary* locations = invoke->GetLocations(); |
| 2175 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2176 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2177 | Location receiver = locations->InAt(0); |
| 2178 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2179 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2180 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2181 | // won't be modified thereafter, before the `call` instruction. |
| 2182 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2183 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2184 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2185 | if (receiver.IsStackSlot()) { |
| 2186 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2187 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2188 | __ movl(temp, Address(temp, class_offset)); |
| 2189 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2190 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2191 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2192 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2193 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2194 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2195 | // emit a read barrier for the previous class reference load. |
| 2196 | // However this is not required in practice, as this is an |
| 2197 | // intermediate/temporary reference and because the current |
| 2198 | // concurrent copying collector keeps the from-space memory |
| 2199 | // intact/accessible until the end of the marking phase (the |
| 2200 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2201 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2202 | // temp = temp->GetAddressOfIMT() |
| 2203 | __ movq(temp, |
| 2204 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2205 | // temp = temp->GetImtEntryAt(method_offset); |
| 2206 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2207 | invoke->GetImtIndex(), kX86_64PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2208 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2209 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2210 | // call temp->GetEntryPoint(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2211 | __ call(Address( |
| 2212 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2213 | |
| 2214 | DCHECK(!codegen_->IsLeafMethod()); |
| 2215 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2216 | } |
| 2217 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2218 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2219 | LocationSummary* locations = |
| 2220 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2221 | switch (neg->GetResultType()) { |
| 2222 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2223 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2224 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2225 | locations->SetOut(Location::SameAsFirstInput()); |
| 2226 | break; |
| 2227 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2228 | case Primitive::kPrimFloat: |
| 2229 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2230 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2231 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2232 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2233 | break; |
| 2234 | |
| 2235 | default: |
| 2236 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2237 | } |
| 2238 | } |
| 2239 | |
| 2240 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2241 | LocationSummary* locations = neg->GetLocations(); |
| 2242 | Location out = locations->Out(); |
| 2243 | Location in = locations->InAt(0); |
| 2244 | switch (neg->GetResultType()) { |
| 2245 | case Primitive::kPrimInt: |
| 2246 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2247 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2248 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2249 | break; |
| 2250 | |
| 2251 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2252 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2253 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2254 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2255 | break; |
| 2256 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2257 | case Primitive::kPrimFloat: { |
| 2258 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2259 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2260 | // Implement float negation with an exclusive or with value |
| 2261 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2262 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2263 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2264 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2265 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2266 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2267 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2268 | case Primitive::kPrimDouble: { |
| 2269 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2270 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2271 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2272 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2273 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2274 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2275 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2276 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2277 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2278 | |
| 2279 | default: |
| 2280 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2281 | } |
| 2282 | } |
| 2283 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2284 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2285 | LocationSummary* locations = |
| 2286 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2287 | Primitive::Type result_type = conversion->GetResultType(); |
| 2288 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2289 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2290 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2291 | // The Java language does not allow treating boolean as an integral type but |
| 2292 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2293 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2294 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2295 | case Primitive::kPrimByte: |
| 2296 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2297 | case Primitive::kPrimLong: |
| 2298 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2299 | case Primitive::kPrimBoolean: |
| 2300 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2301 | case Primitive::kPrimShort: |
| 2302 | case Primitive::kPrimInt: |
| 2303 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2304 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2305 | locations->SetInAt(0, Location::Any()); |
| 2306 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2307 | break; |
| 2308 | |
| 2309 | default: |
| 2310 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2311 | << " to " << result_type; |
| 2312 | } |
| 2313 | break; |
| 2314 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2315 | case Primitive::kPrimShort: |
| 2316 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2317 | case Primitive::kPrimLong: |
| 2318 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2319 | case Primitive::kPrimBoolean: |
| 2320 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2321 | case Primitive::kPrimByte: |
| 2322 | case Primitive::kPrimInt: |
| 2323 | case Primitive::kPrimChar: |
| 2324 | // Processing a Dex `int-to-short' instruction. |
| 2325 | locations->SetInAt(0, Location::Any()); |
| 2326 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2327 | break; |
| 2328 | |
| 2329 | default: |
| 2330 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2331 | << " to " << result_type; |
| 2332 | } |
| 2333 | break; |
| 2334 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2335 | case Primitive::kPrimInt: |
| 2336 | switch (input_type) { |
| 2337 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2338 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2339 | locations->SetInAt(0, Location::Any()); |
| 2340 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2341 | break; |
| 2342 | |
| 2343 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2344 | // Processing a Dex `float-to-int' instruction. |
| 2345 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2346 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2347 | break; |
| 2348 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2349 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2350 | // Processing a Dex `double-to-int' instruction. |
| 2351 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2352 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2353 | break; |
| 2354 | |
| 2355 | default: |
| 2356 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2357 | << " to " << result_type; |
| 2358 | } |
| 2359 | break; |
| 2360 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2361 | case Primitive::kPrimLong: |
| 2362 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2363 | case Primitive::kPrimBoolean: |
| 2364 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimByte: |
| 2366 | case Primitive::kPrimShort: |
| 2367 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2368 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2369 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2370 | // TODO: We would benefit from a (to-be-implemented) |
| 2371 | // Location::RegisterOrStackSlot requirement for this input. |
| 2372 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2373 | locations->SetOut(Location::RequiresRegister()); |
| 2374 | break; |
| 2375 | |
| 2376 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2377 | // Processing a Dex `float-to-long' instruction. |
| 2378 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2379 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2380 | break; |
| 2381 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2382 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2383 | // Processing a Dex `double-to-long' instruction. |
| 2384 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2385 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2386 | break; |
| 2387 | |
| 2388 | default: |
| 2389 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2390 | << " to " << result_type; |
| 2391 | } |
| 2392 | break; |
| 2393 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2394 | case Primitive::kPrimChar: |
| 2395 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2396 | case Primitive::kPrimLong: |
| 2397 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2398 | case Primitive::kPrimBoolean: |
| 2399 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2400 | case Primitive::kPrimByte: |
| 2401 | case Primitive::kPrimShort: |
| 2402 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2403 | // Processing a Dex `int-to-char' instruction. |
| 2404 | locations->SetInAt(0, Location::Any()); |
| 2405 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2406 | break; |
| 2407 | |
| 2408 | default: |
| 2409 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2410 | << " to " << result_type; |
| 2411 | } |
| 2412 | break; |
| 2413 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2414 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2415 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2416 | case Primitive::kPrimBoolean: |
| 2417 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2418 | case Primitive::kPrimByte: |
| 2419 | case Primitive::kPrimShort: |
| 2420 | case Primitive::kPrimInt: |
| 2421 | case Primitive::kPrimChar: |
| 2422 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2423 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2424 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2425 | break; |
| 2426 | |
| 2427 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2428 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2429 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2430 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2431 | break; |
| 2432 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2433 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2434 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2435 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2436 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2437 | break; |
| 2438 | |
| 2439 | default: |
| 2440 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2441 | << " to " << result_type; |
| 2442 | }; |
| 2443 | break; |
| 2444 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2445 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2446 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2447 | case Primitive::kPrimBoolean: |
| 2448 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2449 | case Primitive::kPrimByte: |
| 2450 | case Primitive::kPrimShort: |
| 2451 | case Primitive::kPrimInt: |
| 2452 | case Primitive::kPrimChar: |
| 2453 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2454 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2455 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2456 | break; |
| 2457 | |
| 2458 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2459 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2460 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2461 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2462 | break; |
| 2463 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2464 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2465 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2466 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2467 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2468 | break; |
| 2469 | |
| 2470 | default: |
| 2471 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2472 | << " to " << result_type; |
| 2473 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2474 | break; |
| 2475 | |
| 2476 | default: |
| 2477 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2478 | << " to " << result_type; |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2483 | LocationSummary* locations = conversion->GetLocations(); |
| 2484 | Location out = locations->Out(); |
| 2485 | Location in = locations->InAt(0); |
| 2486 | Primitive::Type result_type = conversion->GetResultType(); |
| 2487 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2488 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2489 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2490 | case Primitive::kPrimByte: |
| 2491 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2492 | case Primitive::kPrimLong: |
| 2493 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2494 | case Primitive::kPrimBoolean: |
| 2495 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2496 | case Primitive::kPrimShort: |
| 2497 | case Primitive::kPrimInt: |
| 2498 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2499 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2500 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2501 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2502 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2503 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2504 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2505 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2506 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2507 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2508 | } |
| 2509 | break; |
| 2510 | |
| 2511 | default: |
| 2512 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2513 | << " to " << result_type; |
| 2514 | } |
| 2515 | break; |
| 2516 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2517 | case Primitive::kPrimShort: |
| 2518 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2519 | case Primitive::kPrimLong: |
| 2520 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2521 | case Primitive::kPrimBoolean: |
| 2522 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2523 | case Primitive::kPrimByte: |
| 2524 | case Primitive::kPrimInt: |
| 2525 | case Primitive::kPrimChar: |
| 2526 | // Processing a Dex `int-to-short' instruction. |
| 2527 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2528 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2529 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2530 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2531 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2532 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2533 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2534 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2535 | } |
| 2536 | break; |
| 2537 | |
| 2538 | default: |
| 2539 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2540 | << " to " << result_type; |
| 2541 | } |
| 2542 | break; |
| 2543 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2544 | case Primitive::kPrimInt: |
| 2545 | switch (input_type) { |
| 2546 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2547 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2548 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2549 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2550 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2551 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2552 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2553 | } else { |
| 2554 | DCHECK(in.IsConstant()); |
| 2555 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2556 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2557 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2558 | } |
| 2559 | break; |
| 2560 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2561 | case Primitive::kPrimFloat: { |
| 2562 | // Processing a Dex `float-to-int' instruction. |
| 2563 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2564 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2565 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2566 | |
| 2567 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2568 | // if input >= (float)INT_MAX goto done |
| 2569 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2570 | __ j(kAboveEqual, &done); |
| 2571 | // if input == NaN goto nan |
| 2572 | __ j(kUnordered, &nan); |
| 2573 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2574 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2575 | __ jmp(&done); |
| 2576 | __ Bind(&nan); |
| 2577 | // output = 0 |
| 2578 | __ xorl(output, output); |
| 2579 | __ Bind(&done); |
| 2580 | break; |
| 2581 | } |
| 2582 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2583 | case Primitive::kPrimDouble: { |
| 2584 | // Processing a Dex `double-to-int' instruction. |
| 2585 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2586 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2587 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2588 | |
| 2589 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2590 | // if input >= (double)INT_MAX goto done |
| 2591 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2592 | __ j(kAboveEqual, &done); |
| 2593 | // if input == NaN goto nan |
| 2594 | __ j(kUnordered, &nan); |
| 2595 | // output = double-to-int-truncate(input) |
| 2596 | __ cvttsd2si(output, input); |
| 2597 | __ jmp(&done); |
| 2598 | __ Bind(&nan); |
| 2599 | // output = 0 |
| 2600 | __ xorl(output, output); |
| 2601 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2602 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2603 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2604 | |
| 2605 | default: |
| 2606 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2607 | << " to " << result_type; |
| 2608 | } |
| 2609 | break; |
| 2610 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2611 | case Primitive::kPrimLong: |
| 2612 | switch (input_type) { |
| 2613 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2614 | case Primitive::kPrimBoolean: |
| 2615 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2616 | case Primitive::kPrimByte: |
| 2617 | case Primitive::kPrimShort: |
| 2618 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2619 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2620 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2621 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2622 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2623 | break; |
| 2624 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2625 | case Primitive::kPrimFloat: { |
| 2626 | // Processing a Dex `float-to-long' instruction. |
| 2627 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2628 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2629 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2630 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2631 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2632 | // if input >= (float)LONG_MAX goto done |
| 2633 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2634 | __ j(kAboveEqual, &done); |
| 2635 | // if input == NaN goto nan |
| 2636 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2637 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2638 | __ cvttss2si(output, input, true); |
| 2639 | __ jmp(&done); |
| 2640 | __ Bind(&nan); |
| 2641 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2642 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2643 | __ Bind(&done); |
| 2644 | break; |
| 2645 | } |
| 2646 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2647 | case Primitive::kPrimDouble: { |
| 2648 | // Processing a Dex `double-to-long' instruction. |
| 2649 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2650 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2651 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2652 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2653 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2654 | // if input >= (double)LONG_MAX goto done |
| 2655 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2656 | __ j(kAboveEqual, &done); |
| 2657 | // if input == NaN goto nan |
| 2658 | __ j(kUnordered, &nan); |
| 2659 | // output = double-to-long-truncate(input) |
| 2660 | __ cvttsd2si(output, input, true); |
| 2661 | __ jmp(&done); |
| 2662 | __ Bind(&nan); |
| 2663 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2664 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2665 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2666 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2667 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2668 | |
| 2669 | default: |
| 2670 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2671 | << " to " << result_type; |
| 2672 | } |
| 2673 | break; |
| 2674 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2675 | case Primitive::kPrimChar: |
| 2676 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2677 | case Primitive::kPrimLong: |
| 2678 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2679 | case Primitive::kPrimBoolean: |
| 2680 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2681 | case Primitive::kPrimByte: |
| 2682 | case Primitive::kPrimShort: |
| 2683 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2684 | // Processing a Dex `int-to-char' instruction. |
| 2685 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2686 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2687 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2688 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2689 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2690 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2691 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2692 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2693 | } |
| 2694 | break; |
| 2695 | |
| 2696 | default: |
| 2697 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2698 | << " to " << result_type; |
| 2699 | } |
| 2700 | break; |
| 2701 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2702 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2703 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2704 | case Primitive::kPrimBoolean: |
| 2705 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2706 | case Primitive::kPrimByte: |
| 2707 | case Primitive::kPrimShort: |
| 2708 | case Primitive::kPrimInt: |
| 2709 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2710 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2711 | if (in.IsRegister()) { |
| 2712 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2713 | } else if (in.IsConstant()) { |
| 2714 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2715 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2716 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2717 | } else { |
| 2718 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2719 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2720 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2721 | break; |
| 2722 | |
| 2723 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2724 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2725 | if (in.IsRegister()) { |
| 2726 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2727 | } else if (in.IsConstant()) { |
| 2728 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2729 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2730 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2731 | } else { |
| 2732 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2733 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2734 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2735 | break; |
| 2736 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2737 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2738 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2739 | if (in.IsFpuRegister()) { |
| 2740 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2741 | } else if (in.IsConstant()) { |
| 2742 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2743 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2744 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2745 | } else { |
| 2746 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2747 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2748 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2749 | break; |
| 2750 | |
| 2751 | default: |
| 2752 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2753 | << " to " << result_type; |
| 2754 | }; |
| 2755 | break; |
| 2756 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2757 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2758 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2759 | case Primitive::kPrimBoolean: |
| 2760 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2761 | case Primitive::kPrimByte: |
| 2762 | case Primitive::kPrimShort: |
| 2763 | case Primitive::kPrimInt: |
| 2764 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2765 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2766 | if (in.IsRegister()) { |
| 2767 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2768 | } else if (in.IsConstant()) { |
| 2769 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2770 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2771 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2772 | } else { |
| 2773 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2774 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2775 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2776 | break; |
| 2777 | |
| 2778 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2779 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2780 | if (in.IsRegister()) { |
| 2781 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2782 | } else if (in.IsConstant()) { |
| 2783 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2784 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2785 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2786 | } else { |
| 2787 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2788 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2789 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2790 | break; |
| 2791 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2792 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2793 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2794 | if (in.IsFpuRegister()) { |
| 2795 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2796 | } else if (in.IsConstant()) { |
| 2797 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2798 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2799 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2800 | } else { |
| 2801 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2802 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2803 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2804 | break; |
| 2805 | |
| 2806 | default: |
| 2807 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2808 | << " to " << result_type; |
| 2809 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2810 | break; |
| 2811 | |
| 2812 | default: |
| 2813 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2814 | << " to " << result_type; |
| 2815 | } |
| 2816 | } |
| 2817 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2818 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2819 | LocationSummary* locations = |
| 2820 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2821 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2822 | case Primitive::kPrimInt: { |
| 2823 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2824 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2825 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2826 | break; |
| 2827 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2828 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2829 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2830 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2831 | // 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] | 2832 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2833 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2834 | break; |
| 2835 | } |
| 2836 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2837 | case Primitive::kPrimDouble: |
| 2838 | case Primitive::kPrimFloat: { |
| 2839 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2840 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2841 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2842 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2843 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2844 | |
| 2845 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2846 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2847 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2851 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2852 | Location first = locations->InAt(0); |
| 2853 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2854 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2855 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2856 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2857 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2858 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2859 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2860 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2861 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2862 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2863 | } else { |
| 2864 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2865 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2866 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2867 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2868 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2869 | __ addl(out.AsRegister<CpuRegister>(), |
| 2870 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2871 | } else { |
| 2872 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2873 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2874 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2875 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2876 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2877 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2878 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2879 | break; |
| 2880 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2881 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2882 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2883 | if (second.IsRegister()) { |
| 2884 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2885 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2886 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2887 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2888 | } else { |
| 2889 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2890 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2891 | } |
| 2892 | } else { |
| 2893 | DCHECK(second.IsConstant()); |
| 2894 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2895 | int32_t int32_value = Low32Bits(value); |
| 2896 | DCHECK_EQ(int32_value, value); |
| 2897 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2898 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2899 | } else { |
| 2900 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2901 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2902 | } |
| 2903 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2904 | break; |
| 2905 | } |
| 2906 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2907 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2908 | if (second.IsFpuRegister()) { |
| 2909 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2910 | } else if (second.IsConstant()) { |
| 2911 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2912 | codegen_->LiteralFloatAddress( |
| 2913 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2914 | } else { |
| 2915 | DCHECK(second.IsStackSlot()); |
| 2916 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2917 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2918 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2919 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2920 | } |
| 2921 | |
| 2922 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2923 | if (second.IsFpuRegister()) { |
| 2924 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2925 | } else if (second.IsConstant()) { |
| 2926 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2927 | codegen_->LiteralDoubleAddress( |
| 2928 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2929 | } else { |
| 2930 | DCHECK(second.IsDoubleStackSlot()); |
| 2931 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2932 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2933 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2934 | break; |
| 2935 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2936 | |
| 2937 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2938 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2943 | LocationSummary* locations = |
| 2944 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2945 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2946 | case Primitive::kPrimInt: { |
| 2947 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2948 | locations->SetInAt(1, Location::Any()); |
| 2949 | locations->SetOut(Location::SameAsFirstInput()); |
| 2950 | break; |
| 2951 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2952 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2953 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 2954 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2955 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2956 | break; |
| 2957 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2958 | case Primitive::kPrimFloat: |
| 2959 | case Primitive::kPrimDouble: { |
| 2960 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2961 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2962 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2963 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2964 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2965 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2966 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2967 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 2971 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2972 | Location first = locations->InAt(0); |
| 2973 | Location second = locations->InAt(1); |
| 2974 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2975 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2976 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2977 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2978 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2979 | } else if (second.IsConstant()) { |
| 2980 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2981 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2982 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2983 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2984 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2985 | break; |
| 2986 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2987 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2988 | if (second.IsConstant()) { |
| 2989 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2990 | DCHECK(IsInt<32>(value)); |
| 2991 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 2992 | } else { |
| 2993 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 2994 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2995 | break; |
| 2996 | } |
| 2997 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2998 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2999 | if (second.IsFpuRegister()) { |
| 3000 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3001 | } else if (second.IsConstant()) { |
| 3002 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3003 | codegen_->LiteralFloatAddress( |
| 3004 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3005 | } else { |
| 3006 | DCHECK(second.IsStackSlot()); |
| 3007 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3008 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3009 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3010 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3014 | if (second.IsFpuRegister()) { |
| 3015 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3016 | } else if (second.IsConstant()) { |
| 3017 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3018 | codegen_->LiteralDoubleAddress( |
| 3019 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3020 | } else { |
| 3021 | DCHECK(second.IsDoubleStackSlot()); |
| 3022 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3023 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3024 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3025 | break; |
| 3026 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3027 | |
| 3028 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3029 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3030 | } |
| 3031 | } |
| 3032 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3033 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3034 | LocationSummary* locations = |
| 3035 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3036 | switch (mul->GetResultType()) { |
| 3037 | case Primitive::kPrimInt: { |
| 3038 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3039 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3040 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3041 | // Can use 3 operand multiply. |
| 3042 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3043 | } else { |
| 3044 | locations->SetOut(Location::SameAsFirstInput()); |
| 3045 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3046 | break; |
| 3047 | } |
| 3048 | case Primitive::kPrimLong: { |
| 3049 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3050 | locations->SetInAt(1, Location::Any()); |
| 3051 | if (mul->InputAt(1)->IsLongConstant() && |
| 3052 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3053 | // Can use 3 operand multiply. |
| 3054 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3055 | } else { |
| 3056 | locations->SetOut(Location::SameAsFirstInput()); |
| 3057 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3058 | break; |
| 3059 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3060 | case Primitive::kPrimFloat: |
| 3061 | case Primitive::kPrimDouble: { |
| 3062 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3063 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3064 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3065 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3066 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3067 | |
| 3068 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3069 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3070 | } |
| 3071 | } |
| 3072 | |
| 3073 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3074 | LocationSummary* locations = mul->GetLocations(); |
| 3075 | Location first = locations->InAt(0); |
| 3076 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3077 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3078 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3079 | case Primitive::kPrimInt: |
| 3080 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3081 | // problems where the output may not be the same as the first operand. |
| 3082 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3083 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3084 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3085 | } else if (second.IsRegister()) { |
| 3086 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3087 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3088 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3089 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3090 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3091 | __ imull(first.AsRegister<CpuRegister>(), |
| 3092 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3093 | } |
| 3094 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3095 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3096 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3097 | // problems where the output may not be the same as the first operand. |
| 3098 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3099 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3100 | if (IsInt<32>(value)) { |
| 3101 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3102 | Immediate(static_cast<int32_t>(value))); |
| 3103 | } else { |
| 3104 | // Have to use the constant area. |
| 3105 | DCHECK(first.Equals(out)); |
| 3106 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3107 | } |
| 3108 | } else if (second.IsRegister()) { |
| 3109 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3110 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3111 | } else { |
| 3112 | DCHECK(second.IsDoubleStackSlot()); |
| 3113 | DCHECK(first.Equals(out)); |
| 3114 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3115 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3116 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3117 | break; |
| 3118 | } |
| 3119 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3120 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3121 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3122 | if (second.IsFpuRegister()) { |
| 3123 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3124 | } else if (second.IsConstant()) { |
| 3125 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3126 | codegen_->LiteralFloatAddress( |
| 3127 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3128 | } else { |
| 3129 | DCHECK(second.IsStackSlot()); |
| 3130 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3131 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3132 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3133 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3137 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3138 | if (second.IsFpuRegister()) { |
| 3139 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3140 | } else if (second.IsConstant()) { |
| 3141 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3142 | codegen_->LiteralDoubleAddress( |
| 3143 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3144 | } else { |
| 3145 | DCHECK(second.IsDoubleStackSlot()); |
| 3146 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3147 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3148 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3149 | break; |
| 3150 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3151 | |
| 3152 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3153 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3154 | } |
| 3155 | } |
| 3156 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3157 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3158 | uint32_t stack_adjustment, bool is_float) { |
| 3159 | if (source.IsStackSlot()) { |
| 3160 | DCHECK(is_float); |
| 3161 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3162 | } else if (source.IsDoubleStackSlot()) { |
| 3163 | DCHECK(!is_float); |
| 3164 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3165 | } else { |
| 3166 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3167 | if (is_float) { |
| 3168 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3169 | codegen_->Move(stack_temp, source); |
| 3170 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3171 | } else { |
| 3172 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3173 | codegen_->Move(stack_temp, source); |
| 3174 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3175 | } |
| 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3180 | Primitive::Type type = rem->GetResultType(); |
| 3181 | bool is_float = type == Primitive::kPrimFloat; |
| 3182 | size_t elem_size = Primitive::ComponentSize(type); |
| 3183 | LocationSummary* locations = rem->GetLocations(); |
| 3184 | Location first = locations->InAt(0); |
| 3185 | Location second = locations->InAt(1); |
| 3186 | Location out = locations->Out(); |
| 3187 | |
| 3188 | // Create stack space for 2 elements. |
| 3189 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3190 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3191 | |
| 3192 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3193 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3194 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3195 | |
| 3196 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3197 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3198 | __ Bind(&retry); |
| 3199 | __ fprem(); |
| 3200 | |
| 3201 | // Move FP status to AX. |
| 3202 | __ fstsw(); |
| 3203 | |
| 3204 | // And see if the argument reduction is complete. This is signaled by the |
| 3205 | // C2 FPU flag bit set to 0. |
| 3206 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3207 | __ j(kNotEqual, &retry); |
| 3208 | |
| 3209 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3210 | // Store FP top of stack to real stack. |
| 3211 | if (is_float) { |
| 3212 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3213 | } else { |
| 3214 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3215 | } |
| 3216 | |
| 3217 | // Pop the 2 items from the FP stack. |
| 3218 | __ fucompp(); |
| 3219 | |
| 3220 | // Load the value from the stack into an XMM register. |
| 3221 | DCHECK(out.IsFpuRegister()) << out; |
| 3222 | if (is_float) { |
| 3223 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3224 | } else { |
| 3225 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3226 | } |
| 3227 | |
| 3228 | // And remove the temporary stack space we allocated. |
| 3229 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3230 | } |
| 3231 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3232 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3233 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3234 | |
| 3235 | LocationSummary* locations = instruction->GetLocations(); |
| 3236 | Location second = locations->InAt(1); |
| 3237 | DCHECK(second.IsConstant()); |
| 3238 | |
| 3239 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3240 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3241 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3242 | |
| 3243 | DCHECK(imm == 1 || imm == -1); |
| 3244 | |
| 3245 | switch (instruction->GetResultType()) { |
| 3246 | case Primitive::kPrimInt: { |
| 3247 | if (instruction->IsRem()) { |
| 3248 | __ xorl(output_register, output_register); |
| 3249 | } else { |
| 3250 | __ movl(output_register, input_register); |
| 3251 | if (imm == -1) { |
| 3252 | __ negl(output_register); |
| 3253 | } |
| 3254 | } |
| 3255 | break; |
| 3256 | } |
| 3257 | |
| 3258 | case Primitive::kPrimLong: { |
| 3259 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3260 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3261 | } else { |
| 3262 | __ movq(output_register, input_register); |
| 3263 | if (imm == -1) { |
| 3264 | __ negq(output_register); |
| 3265 | } |
| 3266 | } |
| 3267 | break; |
| 3268 | } |
| 3269 | |
| 3270 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3271 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3272 | } |
| 3273 | } |
| 3274 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3275 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3276 | LocationSummary* locations = instruction->GetLocations(); |
| 3277 | Location second = locations->InAt(1); |
| 3278 | |
| 3279 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3280 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3281 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3282 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3283 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3284 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3285 | |
| 3286 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3287 | |
| 3288 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3289 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3290 | __ testl(numerator, numerator); |
| 3291 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3292 | int shift = CTZ(imm); |
| 3293 | __ sarl(tmp, Immediate(shift)); |
| 3294 | |
| 3295 | if (imm < 0) { |
| 3296 | __ negl(tmp); |
| 3297 | } |
| 3298 | |
| 3299 | __ movl(output_register, tmp); |
| 3300 | } else { |
| 3301 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3302 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3303 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3304 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3305 | __ addq(rdx, numerator); |
| 3306 | __ testq(numerator, numerator); |
| 3307 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3308 | int shift = CTZ(imm); |
| 3309 | __ sarq(rdx, Immediate(shift)); |
| 3310 | |
| 3311 | if (imm < 0) { |
| 3312 | __ negq(rdx); |
| 3313 | } |
| 3314 | |
| 3315 | __ movq(output_register, rdx); |
| 3316 | } |
| 3317 | } |
| 3318 | |
| 3319 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3320 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3321 | |
| 3322 | LocationSummary* locations = instruction->GetLocations(); |
| 3323 | Location second = locations->InAt(1); |
| 3324 | |
| 3325 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3326 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3327 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3328 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3329 | : locations->Out().AsRegister<CpuRegister>(); |
| 3330 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3331 | |
| 3332 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3333 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3334 | if (instruction->IsDiv()) { |
| 3335 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3336 | } else { |
| 3337 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3338 | } |
| 3339 | |
| 3340 | int64_t magic; |
| 3341 | int shift; |
| 3342 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3343 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3344 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3345 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3346 | |
| 3347 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3348 | |
| 3349 | __ movl(numerator, eax); |
| 3350 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3351 | __ movl(eax, Immediate(magic)); |
| 3352 | __ imull(numerator); |
| 3353 | |
| 3354 | if (imm > 0 && magic < 0) { |
| 3355 | __ addl(edx, numerator); |
| 3356 | } else if (imm < 0 && magic > 0) { |
| 3357 | __ subl(edx, numerator); |
| 3358 | } |
| 3359 | |
| 3360 | if (shift != 0) { |
| 3361 | __ sarl(edx, Immediate(shift)); |
| 3362 | } |
| 3363 | |
| 3364 | __ movl(eax, edx); |
| 3365 | __ shrl(edx, Immediate(31)); |
| 3366 | __ addl(edx, eax); |
| 3367 | |
| 3368 | if (instruction->IsRem()) { |
| 3369 | __ movl(eax, numerator); |
| 3370 | __ imull(edx, Immediate(imm)); |
| 3371 | __ subl(eax, edx); |
| 3372 | __ movl(edx, eax); |
| 3373 | } else { |
| 3374 | __ movl(eax, edx); |
| 3375 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3376 | } else { |
| 3377 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3378 | |
| 3379 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3380 | |
| 3381 | CpuRegister rax = eax; |
| 3382 | CpuRegister rdx = edx; |
| 3383 | |
| 3384 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3385 | |
| 3386 | // Save the numerator. |
| 3387 | __ movq(numerator, rax); |
| 3388 | |
| 3389 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3390 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3391 | |
| 3392 | // RDX:RAX = magic * numerator |
| 3393 | __ imulq(numerator); |
| 3394 | |
| 3395 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3396 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3397 | __ addq(rdx, numerator); |
| 3398 | } else if (imm < 0 && magic > 0) { |
| 3399 | // RDX -= numerator |
| 3400 | __ subq(rdx, numerator); |
| 3401 | } |
| 3402 | |
| 3403 | // Shift if needed. |
| 3404 | if (shift != 0) { |
| 3405 | __ sarq(rdx, Immediate(shift)); |
| 3406 | } |
| 3407 | |
| 3408 | // RDX += 1 if RDX < 0 |
| 3409 | __ movq(rax, rdx); |
| 3410 | __ shrq(rdx, Immediate(63)); |
| 3411 | __ addq(rdx, rax); |
| 3412 | |
| 3413 | if (instruction->IsRem()) { |
| 3414 | __ movq(rax, numerator); |
| 3415 | |
| 3416 | if (IsInt<32>(imm)) { |
| 3417 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3418 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3419 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3420 | } |
| 3421 | |
| 3422 | __ subq(rax, rdx); |
| 3423 | __ movq(rdx, rax); |
| 3424 | } else { |
| 3425 | __ movq(rax, rdx); |
| 3426 | } |
| 3427 | } |
| 3428 | } |
| 3429 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3430 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3431 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3432 | Primitive::Type type = instruction->GetResultType(); |
| 3433 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3434 | |
| 3435 | bool is_div = instruction->IsDiv(); |
| 3436 | LocationSummary* locations = instruction->GetLocations(); |
| 3437 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3438 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3439 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3440 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3441 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3442 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3443 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3444 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3445 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3446 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3447 | if (imm == 0) { |
| 3448 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3449 | } else if (imm == 1 || imm == -1) { |
| 3450 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3451 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3452 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3453 | } else { |
| 3454 | DCHECK(imm <= -2 || imm >= 2); |
| 3455 | GenerateDivRemWithAnyConstant(instruction); |
| 3456 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3457 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3458 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3459 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3460 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3461 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3462 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3463 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3464 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3465 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3466 | // so it's safe to just use negl instead of more complex comparisons. |
| 3467 | if (type == Primitive::kPrimInt) { |
| 3468 | __ cmpl(second_reg, Immediate(-1)); |
| 3469 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3470 | // edx:eax <- sign-extended of eax |
| 3471 | __ cdq(); |
| 3472 | // eax = quotient, edx = remainder |
| 3473 | __ idivl(second_reg); |
| 3474 | } else { |
| 3475 | __ cmpq(second_reg, Immediate(-1)); |
| 3476 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3477 | // rdx:rax <- sign-extended of rax |
| 3478 | __ cqo(); |
| 3479 | // rax = quotient, rdx = remainder |
| 3480 | __ idivq(second_reg); |
| 3481 | } |
| 3482 | __ Bind(slow_path->GetExitLabel()); |
| 3483 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3484 | } |
| 3485 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3486 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3487 | LocationSummary* locations = |
| 3488 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3489 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3490 | case Primitive::kPrimInt: |
| 3491 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3492 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3493 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3494 | locations->SetOut(Location::SameAsFirstInput()); |
| 3495 | // Intel uses edx:eax as the dividend. |
| 3496 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3497 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3498 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3499 | // output and request another temp. |
| 3500 | if (div->InputAt(1)->IsConstant()) { |
| 3501 | locations->AddTemp(Location::RequiresRegister()); |
| 3502 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3503 | break; |
| 3504 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3505 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3506 | case Primitive::kPrimFloat: |
| 3507 | case Primitive::kPrimDouble: { |
| 3508 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3509 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3510 | locations->SetOut(Location::SameAsFirstInput()); |
| 3511 | break; |
| 3512 | } |
| 3513 | |
| 3514 | default: |
| 3515 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3516 | } |
| 3517 | } |
| 3518 | |
| 3519 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3520 | LocationSummary* locations = div->GetLocations(); |
| 3521 | Location first = locations->InAt(0); |
| 3522 | Location second = locations->InAt(1); |
| 3523 | DCHECK(first.Equals(locations->Out())); |
| 3524 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3525 | Primitive::Type type = div->GetResultType(); |
| 3526 | switch (type) { |
| 3527 | case Primitive::kPrimInt: |
| 3528 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3529 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3530 | break; |
| 3531 | } |
| 3532 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3533 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3534 | if (second.IsFpuRegister()) { |
| 3535 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3536 | } else if (second.IsConstant()) { |
| 3537 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3538 | codegen_->LiteralFloatAddress( |
| 3539 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3540 | } else { |
| 3541 | DCHECK(second.IsStackSlot()); |
| 3542 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3543 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3544 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3545 | break; |
| 3546 | } |
| 3547 | |
| 3548 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3549 | if (second.IsFpuRegister()) { |
| 3550 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3551 | } else if (second.IsConstant()) { |
| 3552 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3553 | codegen_->LiteralDoubleAddress( |
| 3554 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3555 | } else { |
| 3556 | DCHECK(second.IsDoubleStackSlot()); |
| 3557 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3558 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3559 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3560 | break; |
| 3561 | } |
| 3562 | |
| 3563 | default: |
| 3564 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3565 | } |
| 3566 | } |
| 3567 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3568 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3569 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3570 | LocationSummary* locations = |
| 3571 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3572 | |
| 3573 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3574 | case Primitive::kPrimInt: |
| 3575 | case Primitive::kPrimLong: { |
| 3576 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3577 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3578 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3579 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3580 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3581 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3582 | // output and request another temp. |
| 3583 | if (rem->InputAt(1)->IsConstant()) { |
| 3584 | locations->AddTemp(Location::RequiresRegister()); |
| 3585 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3586 | break; |
| 3587 | } |
| 3588 | |
| 3589 | case Primitive::kPrimFloat: |
| 3590 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3591 | locations->SetInAt(0, Location::Any()); |
| 3592 | locations->SetInAt(1, Location::Any()); |
| 3593 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3594 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3595 | break; |
| 3596 | } |
| 3597 | |
| 3598 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3599 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3600 | } |
| 3601 | } |
| 3602 | |
| 3603 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3604 | Primitive::Type type = rem->GetResultType(); |
| 3605 | switch (type) { |
| 3606 | case Primitive::kPrimInt: |
| 3607 | case Primitive::kPrimLong: { |
| 3608 | GenerateDivRemIntegral(rem); |
| 3609 | break; |
| 3610 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3611 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3612 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3613 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3614 | break; |
| 3615 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3616 | default: |
| 3617 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3618 | } |
| 3619 | } |
| 3620 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3621 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3622 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3623 | locations->SetInAt(0, Location::Any()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3627 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3628 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3629 | codegen_->AddSlowPath(slow_path); |
| 3630 | |
| 3631 | LocationSummary* locations = instruction->GetLocations(); |
| 3632 | Location value = locations->InAt(0); |
| 3633 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3634 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3635 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3636 | case Primitive::kPrimByte: |
| 3637 | case Primitive::kPrimChar: |
| 3638 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3639 | case Primitive::kPrimInt: { |
| 3640 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3641 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3642 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3643 | } else if (value.IsStackSlot()) { |
| 3644 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3645 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3646 | } else { |
| 3647 | DCHECK(value.IsConstant()) << value; |
| 3648 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3649 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3650 | } |
| 3651 | } |
| 3652 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3653 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3654 | case Primitive::kPrimLong: { |
| 3655 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3656 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3657 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3658 | } else if (value.IsDoubleStackSlot()) { |
| 3659 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3660 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3661 | } else { |
| 3662 | DCHECK(value.IsConstant()) << value; |
| 3663 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3664 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3665 | } |
| 3666 | } |
| 3667 | break; |
| 3668 | } |
| 3669 | default: |
| 3670 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3671 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3672 | } |
| 3673 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3674 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3675 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3676 | |
| 3677 | LocationSummary* locations = |
| 3678 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3679 | |
| 3680 | switch (op->GetResultType()) { |
| 3681 | case Primitive::kPrimInt: |
| 3682 | case Primitive::kPrimLong: { |
| 3683 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3684 | // The shift count needs to be in CL. |
| 3685 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3686 | locations->SetOut(Location::SameAsFirstInput()); |
| 3687 | break; |
| 3688 | } |
| 3689 | default: |
| 3690 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3691 | } |
| 3692 | } |
| 3693 | |
| 3694 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3695 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3696 | |
| 3697 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3698 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3699 | Location second = locations->InAt(1); |
| 3700 | |
| 3701 | switch (op->GetResultType()) { |
| 3702 | case Primitive::kPrimInt: { |
| 3703 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3704 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3705 | if (op->IsShl()) { |
| 3706 | __ shll(first_reg, second_reg); |
| 3707 | } else if (op->IsShr()) { |
| 3708 | __ sarl(first_reg, second_reg); |
| 3709 | } else { |
| 3710 | __ shrl(first_reg, second_reg); |
| 3711 | } |
| 3712 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3713 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3714 | if (op->IsShl()) { |
| 3715 | __ shll(first_reg, imm); |
| 3716 | } else if (op->IsShr()) { |
| 3717 | __ sarl(first_reg, imm); |
| 3718 | } else { |
| 3719 | __ shrl(first_reg, imm); |
| 3720 | } |
| 3721 | } |
| 3722 | break; |
| 3723 | } |
| 3724 | case Primitive::kPrimLong: { |
| 3725 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3726 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3727 | if (op->IsShl()) { |
| 3728 | __ shlq(first_reg, second_reg); |
| 3729 | } else if (op->IsShr()) { |
| 3730 | __ sarq(first_reg, second_reg); |
| 3731 | } else { |
| 3732 | __ shrq(first_reg, second_reg); |
| 3733 | } |
| 3734 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3735 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3736 | if (op->IsShl()) { |
| 3737 | __ shlq(first_reg, imm); |
| 3738 | } else if (op->IsShr()) { |
| 3739 | __ sarq(first_reg, imm); |
| 3740 | } else { |
| 3741 | __ shrq(first_reg, imm); |
| 3742 | } |
| 3743 | } |
| 3744 | break; |
| 3745 | } |
| 3746 | default: |
| 3747 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3748 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3749 | } |
| 3750 | } |
| 3751 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3752 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3753 | LocationSummary* locations = |
| 3754 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3755 | |
| 3756 | switch (ror->GetResultType()) { |
| 3757 | case Primitive::kPrimInt: |
| 3758 | case Primitive::kPrimLong: { |
| 3759 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3760 | // The shift count needs to be in CL (unless it is a constant). |
| 3761 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3762 | locations->SetOut(Location::SameAsFirstInput()); |
| 3763 | break; |
| 3764 | } |
| 3765 | default: |
| 3766 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3767 | UNREACHABLE(); |
| 3768 | } |
| 3769 | } |
| 3770 | |
| 3771 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 3772 | LocationSummary* locations = ror->GetLocations(); |
| 3773 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3774 | Location second = locations->InAt(1); |
| 3775 | |
| 3776 | switch (ror->GetResultType()) { |
| 3777 | case Primitive::kPrimInt: |
| 3778 | if (second.IsRegister()) { |
| 3779 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3780 | __ rorl(first_reg, second_reg); |
| 3781 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3782 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3783 | __ rorl(first_reg, imm); |
| 3784 | } |
| 3785 | break; |
| 3786 | case Primitive::kPrimLong: |
| 3787 | if (second.IsRegister()) { |
| 3788 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3789 | __ rorq(first_reg, second_reg); |
| 3790 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3791 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3792 | __ rorq(first_reg, imm); |
| 3793 | } |
| 3794 | break; |
| 3795 | default: |
| 3796 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3797 | UNREACHABLE(); |
| 3798 | } |
| 3799 | } |
| 3800 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3801 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3802 | HandleShift(shl); |
| 3803 | } |
| 3804 | |
| 3805 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3806 | HandleShift(shl); |
| 3807 | } |
| 3808 | |
| 3809 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3810 | HandleShift(shr); |
| 3811 | } |
| 3812 | |
| 3813 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3814 | HandleShift(shr); |
| 3815 | } |
| 3816 | |
| 3817 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3818 | HandleShift(ushr); |
| 3819 | } |
| 3820 | |
| 3821 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3822 | HandleShift(ushr); |
| 3823 | } |
| 3824 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3825 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3826 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3827 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3828 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3829 | if (instruction->IsStringAlloc()) { |
| 3830 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3831 | } else { |
| 3832 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3833 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3834 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3835 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3839 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3840 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3841 | if (instruction->IsStringAlloc()) { |
| 3842 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3843 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3844 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3845 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 3846 | __ call(Address(temp, code_offset.SizeValue())); |
| 3847 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3848 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3849 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3850 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3851 | DCHECK(!codegen_->IsLeafMethod()); |
| 3852 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3853 | } |
| 3854 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3855 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3856 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3857 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3858 | InvokeRuntimeCallingConvention calling_convention; |
| 3859 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3860 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3861 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3862 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3866 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3867 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3868 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3869 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3870 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3871 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3872 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3873 | |
| 3874 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3875 | } |
| 3876 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3877 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3878 | LocationSummary* locations = |
| 3879 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3880 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3881 | if (location.IsStackSlot()) { |
| 3882 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3883 | } else if (location.IsDoubleStackSlot()) { |
| 3884 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3885 | } |
| 3886 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3887 | } |
| 3888 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3889 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3890 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3891 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3895 | LocationSummary* locations = |
| 3896 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3897 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3898 | } |
| 3899 | |
| 3900 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3901 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3902 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3903 | } |
| 3904 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3905 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3906 | LocationSummary* locations = |
| 3907 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3908 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3909 | locations->SetOut(Location::RequiresRegister()); |
| 3910 | } |
| 3911 | |
| 3912 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3913 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3914 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 3915 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3916 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 3917 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 3918 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3919 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 3920 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3921 | instruction->GetIndex(), kX86_64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3922 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 3923 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 3924 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 3925 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 3926 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3927 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3928 | } |
| 3929 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3930 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3931 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3932 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3933 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3934 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3935 | } |
| 3936 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3937 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3938 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3939 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3940 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3941 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3942 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3943 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3944 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3945 | break; |
| 3946 | |
| 3947 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3948 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3949 | break; |
| 3950 | |
| 3951 | default: |
| 3952 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3953 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3954 | } |
| 3955 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3956 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3957 | LocationSummary* locations = |
| 3958 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3959 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3960 | locations->SetOut(Location::SameAsFirstInput()); |
| 3961 | } |
| 3962 | |
| 3963 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3964 | LocationSummary* locations = bool_not->GetLocations(); |
| 3965 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3966 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3967 | Location out = locations->Out(); |
| 3968 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 3969 | } |
| 3970 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3971 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3972 | LocationSummary* locations = |
| 3973 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3974 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3975 | locations->SetInAt(i, Location::Any()); |
| 3976 | } |
| 3977 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3978 | } |
| 3979 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3980 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3981 | LOG(FATAL) << "Unimplemented"; |
| 3982 | } |
| 3983 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3984 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3985 | /* |
| 3986 | * 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] | 3987 | * 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] | 3988 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3989 | */ |
| 3990 | switch (kind) { |
| 3991 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 3992 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3993 | break; |
| 3994 | } |
| 3995 | case MemBarrierKind::kAnyStore: |
| 3996 | case MemBarrierKind::kLoadAny: |
| 3997 | case MemBarrierKind::kStoreStore: { |
| 3998 | // nop |
| 3999 | break; |
| 4000 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4001 | case MemBarrierKind::kNTStoreStore: |
| 4002 | // Non-Temporal Store/Store needs an explicit fence. |
| 4003 | MemoryFence(/* non-temporal */ true); |
| 4004 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4005 | } |
| 4006 | } |
| 4007 | |
| 4008 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4009 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4010 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4011 | bool object_field_get_with_read_barrier = |
| 4012 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4013 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4014 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4015 | object_field_get_with_read_barrier ? |
| 4016 | LocationSummary::kCallOnSlowPath : |
| 4017 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4018 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4019 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4020 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4021 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4022 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4023 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4024 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4025 | // The output overlaps for an object field get when read barriers |
| 4026 | // are enabled: we do not want the move to overwrite the object's |
| 4027 | // location, as we need it to emit the read barrier. |
| 4028 | locations->SetOut( |
| 4029 | Location::RequiresRegister(), |
| 4030 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4031 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4035 | const FieldInfo& field_info) { |
| 4036 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4037 | |
| 4038 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4039 | Location base_loc = locations->InAt(0); |
| 4040 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4041 | Location out = locations->Out(); |
| 4042 | bool is_volatile = field_info.IsVolatile(); |
| 4043 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4044 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4045 | |
| 4046 | switch (field_type) { |
| 4047 | case Primitive::kPrimBoolean: { |
| 4048 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4049 | break; |
| 4050 | } |
| 4051 | |
| 4052 | case Primitive::kPrimByte: { |
| 4053 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4054 | break; |
| 4055 | } |
| 4056 | |
| 4057 | case Primitive::kPrimShort: { |
| 4058 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4059 | break; |
| 4060 | } |
| 4061 | |
| 4062 | case Primitive::kPrimChar: { |
| 4063 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4064 | break; |
| 4065 | } |
| 4066 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4067 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4068 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4069 | break; |
| 4070 | } |
| 4071 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4072 | case Primitive::kPrimNot: { |
| 4073 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4074 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4075 | // Note that a potential implicit null check is handled in this |
| 4076 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4077 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4078 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4079 | if (is_volatile) { |
| 4080 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4081 | } |
| 4082 | } else { |
| 4083 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4084 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4085 | if (is_volatile) { |
| 4086 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4087 | } |
| 4088 | // If read barriers are enabled, emit read barriers other than |
| 4089 | // Baker's using a slow path (and also unpoison the loaded |
| 4090 | // reference, if heap poisoning is enabled). |
| 4091 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4092 | } |
| 4093 | break; |
| 4094 | } |
| 4095 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4096 | case Primitive::kPrimLong: { |
| 4097 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4098 | break; |
| 4099 | } |
| 4100 | |
| 4101 | case Primitive::kPrimFloat: { |
| 4102 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4103 | break; |
| 4104 | } |
| 4105 | |
| 4106 | case Primitive::kPrimDouble: { |
| 4107 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4108 | break; |
| 4109 | } |
| 4110 | |
| 4111 | case Primitive::kPrimVoid: |
| 4112 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4113 | UNREACHABLE(); |
| 4114 | } |
| 4115 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4116 | if (field_type == Primitive::kPrimNot) { |
| 4117 | // Potential implicit null checks, in the case of reference |
| 4118 | // fields, are handled in the previous switch statement. |
| 4119 | } else { |
| 4120 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4121 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4122 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4123 | if (is_volatile) { |
| 4124 | if (field_type == Primitive::kPrimNot) { |
| 4125 | // Memory barriers, in the case of references, are also handled |
| 4126 | // in the previous switch statement. |
| 4127 | } else { |
| 4128 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4129 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4130 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4134 | const FieldInfo& field_info) { |
| 4135 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4136 | |
| 4137 | LocationSummary* locations = |
| 4138 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4139 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4140 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4141 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4142 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4143 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4144 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4145 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4146 | if (is_volatile) { |
| 4147 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4148 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4149 | } else { |
| 4150 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4151 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4152 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4153 | if (is_volatile) { |
| 4154 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4155 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4156 | } else { |
| 4157 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4158 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4159 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4160 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4161 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4162 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4163 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4164 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4165 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4166 | locations->AddTemp(Location::RequiresRegister()); |
| 4167 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4168 | } |
| 4169 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4170 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4171 | const FieldInfo& field_info, |
| 4172 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4173 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4174 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4175 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4176 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4177 | Location value = locations->InAt(1); |
| 4178 | bool is_volatile = field_info.IsVolatile(); |
| 4179 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4180 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4181 | |
| 4182 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4183 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4184 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4185 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4186 | bool maybe_record_implicit_null_check_done = false; |
| 4187 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4188 | switch (field_type) { |
| 4189 | case Primitive::kPrimBoolean: |
| 4190 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4191 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4192 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4193 | __ movb(Address(base, offset), Immediate(v)); |
| 4194 | } else { |
| 4195 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4196 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4197 | break; |
| 4198 | } |
| 4199 | |
| 4200 | case Primitive::kPrimShort: |
| 4201 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4202 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4203 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4204 | __ movw(Address(base, offset), Immediate(v)); |
| 4205 | } else { |
| 4206 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4207 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4208 | break; |
| 4209 | } |
| 4210 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4211 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4212 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4213 | if (value.IsConstant()) { |
| 4214 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4215 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4216 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4217 | // Note: if heap poisoning is enabled, no need to poison |
| 4218 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4219 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4220 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4221 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4222 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4223 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4224 | __ PoisonHeapReference(temp); |
| 4225 | __ movl(Address(base, offset), temp); |
| 4226 | } else { |
| 4227 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4228 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4229 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4230 | break; |
| 4231 | } |
| 4232 | |
| 4233 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4234 | if (value.IsConstant()) { |
| 4235 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4236 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4237 | Address(base, offset + sizeof(int32_t)), |
| 4238 | v, |
| 4239 | instruction); |
| 4240 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4241 | } else { |
| 4242 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4243 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4244 | break; |
| 4245 | } |
| 4246 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4247 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4248 | if (value.IsConstant()) { |
| 4249 | int32_t v = |
| 4250 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4251 | __ movl(Address(base, offset), Immediate(v)); |
| 4252 | } else { |
| 4253 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4254 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4255 | break; |
| 4256 | } |
| 4257 | |
| 4258 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4259 | if (value.IsConstant()) { |
| 4260 | int64_t v = |
| 4261 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4262 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4263 | Address(base, offset + sizeof(int32_t)), |
| 4264 | v, |
| 4265 | instruction); |
| 4266 | maybe_record_implicit_null_check_done = true; |
| 4267 | } else { |
| 4268 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4269 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4270 | break; |
| 4271 | } |
| 4272 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4273 | case Primitive::kPrimVoid: |
| 4274 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4275 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4276 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4277 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4278 | if (!maybe_record_implicit_null_check_done) { |
| 4279 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4280 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4281 | |
| 4282 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4283 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4284 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4285 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4286 | } |
| 4287 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4288 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4289 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4290 | } |
| 4291 | } |
| 4292 | |
| 4293 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4294 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4295 | } |
| 4296 | |
| 4297 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4298 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4302 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4303 | } |
| 4304 | |
| 4305 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4306 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4307 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4308 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4309 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4310 | HandleFieldGet(instruction); |
| 4311 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4312 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4313 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4314 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4315 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4316 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4317 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4318 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4319 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4320 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4321 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4322 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4323 | } |
| 4324 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4325 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4326 | HUnresolvedInstanceFieldGet* instruction) { |
| 4327 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4328 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4329 | instruction, instruction->GetFieldType(), calling_convention); |
| 4330 | } |
| 4331 | |
| 4332 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4333 | HUnresolvedInstanceFieldGet* instruction) { |
| 4334 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4335 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4336 | instruction->GetFieldType(), |
| 4337 | instruction->GetFieldIndex(), |
| 4338 | instruction->GetDexPc(), |
| 4339 | calling_convention); |
| 4340 | } |
| 4341 | |
| 4342 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4343 | HUnresolvedInstanceFieldSet* instruction) { |
| 4344 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4345 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4346 | instruction, instruction->GetFieldType(), calling_convention); |
| 4347 | } |
| 4348 | |
| 4349 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4350 | HUnresolvedInstanceFieldSet* instruction) { |
| 4351 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4352 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4353 | instruction->GetFieldType(), |
| 4354 | instruction->GetFieldIndex(), |
| 4355 | instruction->GetDexPc(), |
| 4356 | calling_convention); |
| 4357 | } |
| 4358 | |
| 4359 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4360 | HUnresolvedStaticFieldGet* instruction) { |
| 4361 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4362 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4363 | instruction, instruction->GetFieldType(), calling_convention); |
| 4364 | } |
| 4365 | |
| 4366 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4367 | HUnresolvedStaticFieldGet* instruction) { |
| 4368 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4369 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4370 | instruction->GetFieldType(), |
| 4371 | instruction->GetFieldIndex(), |
| 4372 | instruction->GetDexPc(), |
| 4373 | calling_convention); |
| 4374 | } |
| 4375 | |
| 4376 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4377 | HUnresolvedStaticFieldSet* instruction) { |
| 4378 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4379 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4380 | instruction, instruction->GetFieldType(), calling_convention); |
| 4381 | } |
| 4382 | |
| 4383 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4384 | HUnresolvedStaticFieldSet* instruction) { |
| 4385 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4386 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4387 | instruction->GetFieldType(), |
| 4388 | instruction->GetFieldIndex(), |
| 4389 | instruction->GetDexPc(), |
| 4390 | calling_convention); |
| 4391 | } |
| 4392 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4393 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4394 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4395 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4396 | ? Location::RequiresRegister() |
| 4397 | : Location::Any(); |
| 4398 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4399 | } |
| 4400 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4401 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4402 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4403 | return; |
| 4404 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4405 | LocationSummary* locations = instruction->GetLocations(); |
| 4406 | Location obj = locations->InAt(0); |
| 4407 | |
| 4408 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4409 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4410 | } |
| 4411 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4412 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4413 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4414 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4415 | |
| 4416 | LocationSummary* locations = instruction->GetLocations(); |
| 4417 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4418 | |
| 4419 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4420 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4421 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4422 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4423 | } else { |
| 4424 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4425 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4426 | __ jmp(slow_path->GetEntryLabel()); |
| 4427 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4428 | } |
| 4429 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4430 | } |
| 4431 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4432 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4433 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4434 | } |
| 4435 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4436 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4437 | bool object_array_get_with_read_barrier = |
| 4438 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4439 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4440 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4441 | object_array_get_with_read_barrier ? |
| 4442 | LocationSummary::kCallOnSlowPath : |
| 4443 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4444 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4445 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4446 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4447 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4448 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4449 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4450 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4451 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4452 | // The output overlaps for an object array get when read barriers |
| 4453 | // are enabled: we do not want the move to overwrite the array's |
| 4454 | // location, as we need it to emit the read barrier. |
| 4455 | locations->SetOut( |
| 4456 | Location::RequiresRegister(), |
| 4457 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4458 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4459 | } |
| 4460 | |
| 4461 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4462 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4463 | Location obj_loc = locations->InAt(0); |
| 4464 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4465 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4466 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4467 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4468 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4469 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4470 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4471 | case Primitive::kPrimBoolean: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4472 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4473 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4474 | break; |
| 4475 | } |
| 4476 | |
| 4477 | case Primitive::kPrimByte: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4478 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4479 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4480 | break; |
| 4481 | } |
| 4482 | |
| 4483 | case Primitive::kPrimShort: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4484 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4485 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4486 | break; |
| 4487 | } |
| 4488 | |
| 4489 | case Primitive::kPrimChar: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4490 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame^] | 4491 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 4492 | // Branch cases into compressed and uncompressed for each index's type. |
| 4493 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4494 | NearLabel done, not_compressed; |
| 4495 | __ cmpl(Address(obj, count_offset), Immediate(0)); |
| 4496 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4497 | __ j(kGreaterEqual, ¬_compressed); |
| 4498 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 4499 | __ jmp(&done); |
| 4500 | __ Bind(¬_compressed); |
| 4501 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4502 | __ Bind(&done); |
| 4503 | } else { |
| 4504 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 4505 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4506 | break; |
| 4507 | } |
| 4508 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4509 | case Primitive::kPrimInt: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4510 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4511 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4512 | break; |
| 4513 | } |
| 4514 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4515 | case Primitive::kPrimNot: { |
| 4516 | static_assert( |
| 4517 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4518 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4519 | // /* HeapReference<Object> */ out = |
| 4520 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4521 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4522 | // Note that a potential implicit null check is handled in this |
| 4523 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4524 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4525 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4526 | } else { |
| 4527 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4528 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 4529 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4530 | // If read barriers are enabled, emit read barriers other than |
| 4531 | // Baker's using a slow path (and also unpoison the loaded |
| 4532 | // reference, if heap poisoning is enabled). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4533 | if (index.IsConstant()) { |
| 4534 | uint32_t offset = |
| 4535 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4536 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4537 | } else { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4538 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4539 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4540 | } |
| 4541 | } |
| 4542 | break; |
| 4543 | } |
| 4544 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4545 | case Primitive::kPrimLong: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4546 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4547 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4548 | break; |
| 4549 | } |
| 4550 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4551 | case Primitive::kPrimFloat: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4552 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4553 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4554 | break; |
| 4555 | } |
| 4556 | |
| 4557 | case Primitive::kPrimDouble: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4558 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4559 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4560 | break; |
| 4561 | } |
| 4562 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4563 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4564 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4565 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4566 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4567 | |
| 4568 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4569 | // Potential implicit null checks, in the case of reference |
| 4570 | // arrays, are handled in the previous switch statement. |
| 4571 | } else { |
| 4572 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4573 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4577 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4578 | |
| 4579 | bool needs_write_barrier = |
| 4580 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4581 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4582 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4583 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4584 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4585 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4586 | LocationSummary::kCallOnSlowPath : |
| 4587 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4588 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4589 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4590 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4591 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4592 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4593 | } else { |
| 4594 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4595 | } |
| 4596 | |
| 4597 | if (needs_write_barrier) { |
| 4598 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4599 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4600 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4601 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4605 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4606 | Location array_loc = locations->InAt(0); |
| 4607 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4608 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4609 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4610 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4611 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4612 | bool needs_write_barrier = |
| 4613 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4614 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4615 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4616 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4617 | |
| 4618 | switch (value_type) { |
| 4619 | case Primitive::kPrimBoolean: |
| 4620 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4621 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4622 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4623 | if (value.IsRegister()) { |
| 4624 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4625 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4626 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4627 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4628 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4629 | break; |
| 4630 | } |
| 4631 | |
| 4632 | case Primitive::kPrimShort: |
| 4633 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4634 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4635 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4636 | if (value.IsRegister()) { |
| 4637 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4638 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4639 | DCHECK(value.IsConstant()) << value; |
| 4640 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4641 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4642 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4643 | break; |
| 4644 | } |
| 4645 | |
| 4646 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4647 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4648 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4649 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4650 | if (!value.IsRegister()) { |
| 4651 | // Just setting null. |
| 4652 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4653 | DCHECK(value.IsConstant()) << value; |
| 4654 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4655 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4656 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4657 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4658 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4659 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4660 | |
| 4661 | DCHECK(needs_write_barrier); |
| 4662 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4663 | // We cannot use a NearLabel for `done`, as its range may be too |
| 4664 | // short when Baker read barriers are enabled. |
| 4665 | Label done; |
| 4666 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4667 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4668 | Location temp_loc = locations->GetTemp(0); |
| 4669 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4670 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4671 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4672 | codegen_->AddSlowPath(slow_path); |
| 4673 | if (instruction->GetValueCanBeNull()) { |
| 4674 | __ testl(register_value, register_value); |
| 4675 | __ j(kNotEqual, ¬_null); |
| 4676 | __ movl(address, Immediate(0)); |
| 4677 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4678 | __ jmp(&done); |
| 4679 | __ Bind(¬_null); |
| 4680 | } |
| 4681 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4682 | // Note that when Baker read barriers are enabled, the type |
| 4683 | // checks are performed without read barriers. This is fine, |
| 4684 | // even in the case where a class object is in the from-space |
| 4685 | // after the flip, as a comparison involving such a type would |
| 4686 | // not produce a false positive; it may of course produce a |
| 4687 | // false negative, in which case we would take the ArraySet |
| 4688 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4689 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4690 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4691 | __ movl(temp, Address(array, class_offset)); |
| 4692 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4693 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4694 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4695 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4696 | __ movl(temp, Address(temp, component_offset)); |
| 4697 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4698 | // nor the object reference in `register_value->klass`, as |
| 4699 | // we are comparing two poisoned references. |
| 4700 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4701 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4702 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4703 | __ j(kEqual, &do_put); |
| 4704 | // If heap poisoning is enabled, the `temp` reference has |
| 4705 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4706 | __ MaybeUnpoisonHeapReference(temp); |
| 4707 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4708 | // If heap poisoning is enabled, no need to unpoison the |
| 4709 | // heap reference loaded below, as it is only used for a |
| 4710 | // comparison with null. |
| 4711 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 4712 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4713 | __ Bind(&do_put); |
| 4714 | } else { |
| 4715 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4716 | } |
| 4717 | } |
| 4718 | |
| 4719 | if (kPoisonHeapReferences) { |
| 4720 | __ movl(temp, register_value); |
| 4721 | __ PoisonHeapReference(temp); |
| 4722 | __ movl(address, temp); |
| 4723 | } else { |
| 4724 | __ movl(address, register_value); |
| 4725 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4726 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4727 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4728 | } |
| 4729 | |
| 4730 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4731 | codegen_->MarkGCCard( |
| 4732 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4733 | __ Bind(&done); |
| 4734 | |
| 4735 | if (slow_path != nullptr) { |
| 4736 | __ Bind(slow_path->GetExitLabel()); |
| 4737 | } |
| 4738 | |
| 4739 | break; |
| 4740 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4741 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4742 | case Primitive::kPrimInt: { |
| 4743 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4744 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4745 | if (value.IsRegister()) { |
| 4746 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4747 | } else { |
| 4748 | DCHECK(value.IsConstant()) << value; |
| 4749 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4750 | __ movl(address, Immediate(v)); |
| 4751 | } |
| 4752 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4753 | break; |
| 4754 | } |
| 4755 | |
| 4756 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4757 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4758 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4759 | if (value.IsRegister()) { |
| 4760 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4761 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4762 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4763 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4764 | Address address_high = |
| 4765 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4766 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4767 | } |
| 4768 | break; |
| 4769 | } |
| 4770 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4771 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4772 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4773 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4774 | if (value.IsFpuRegister()) { |
| 4775 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 4776 | } else { |
| 4777 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4778 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4779 | __ movl(address, Immediate(v)); |
| 4780 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4781 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4782 | break; |
| 4783 | } |
| 4784 | |
| 4785 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4786 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4787 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4788 | if (value.IsFpuRegister()) { |
| 4789 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 4790 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4791 | } else { |
| 4792 | int64_t v = |
| 4793 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4794 | Address address_high = |
| 4795 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4796 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 4797 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4798 | break; |
| 4799 | } |
| 4800 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4801 | case Primitive::kPrimVoid: |
| 4802 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4803 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4804 | } |
| 4805 | } |
| 4806 | |
| 4807 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4808 | LocationSummary* locations = |
| 4809 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4810 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 4811 | if (!instruction->IsEmittedAtUseSite()) { |
| 4812 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4813 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 4817 | if (instruction->IsEmittedAtUseSite()) { |
| 4818 | return; |
| 4819 | } |
| 4820 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4821 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 4822 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4823 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4824 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4825 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4826 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame^] | 4827 | // Mask out most significant bit in case the array is String's array of char. |
| 4828 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 4829 | __ andl(out, Immediate(INT32_MAX)); |
| 4830 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4834 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4835 | InvokeRuntimeCallingConvention calling_convention; |
| 4836 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4837 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4838 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4839 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 4840 | HInstruction* length = instruction->InputAt(1); |
| 4841 | if (!length->IsEmittedAtUseSite()) { |
| 4842 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 4843 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4847 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4848 | Location index_loc = locations->InAt(0); |
| 4849 | Location length_loc = locations->InAt(1); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 4850 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4851 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4852 | if (length_loc.IsConstant()) { |
| 4853 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4854 | if (index_loc.IsConstant()) { |
| 4855 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4856 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4857 | if (index < 0 || index >= length) { |
| 4858 | codegen_->AddSlowPath(slow_path); |
| 4859 | __ jmp(slow_path->GetEntryLabel()); |
| 4860 | } else { |
| 4861 | // Some optimization after BCE may have generated this, and we should not |
| 4862 | // generate a bounds check if it is a valid range. |
| 4863 | } |
| 4864 | return; |
| 4865 | } |
| 4866 | |
| 4867 | // We have to reverse the jump condition because the length is the constant. |
| 4868 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4869 | __ cmpl(index_reg, Immediate(length)); |
| 4870 | codegen_->AddSlowPath(slow_path); |
| 4871 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4872 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 4873 | HInstruction* array_length = instruction->InputAt(1); |
| 4874 | if (array_length->IsEmittedAtUseSite()) { |
| 4875 | // Address the length field in the array. |
| 4876 | DCHECK(array_length->IsArrayLength()); |
| 4877 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 4878 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 4879 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame^] | 4880 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 4881 | CpuRegister length_reg = CpuRegister(TMP); |
| 4882 | __ movl(length_reg, array_len); |
| 4883 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| 4884 | __ andl(length_reg, Immediate(INT32_MAX)); |
| 4885 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 4886 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame^] | 4887 | // Checking the bound for general case: |
| 4888 | // Array of char or String's array when the compression feature off. |
| 4889 | if (index_loc.IsConstant()) { |
| 4890 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4891 | __ cmpl(array_len, Immediate(value)); |
| 4892 | } else { |
| 4893 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 4894 | } |
| 4895 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 4896 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4897 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4898 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4899 | } |
| 4900 | codegen_->AddSlowPath(slow_path); |
| 4901 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4902 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4903 | } |
| 4904 | |
| 4905 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 4906 | CpuRegister card, |
| 4907 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4908 | CpuRegister value, |
| 4909 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4910 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4911 | if (value_can_be_null) { |
| 4912 | __ testl(value, value); |
| 4913 | __ j(kEqual, &is_null); |
| 4914 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4915 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4916 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4917 | __ movq(temp, object); |
| 4918 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4919 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4920 | if (value_can_be_null) { |
| 4921 | __ Bind(&is_null); |
| 4922 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4923 | } |
| 4924 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4925 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4926 | LOG(FATAL) << "Unimplemented"; |
| 4927 | } |
| 4928 | |
| 4929 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4930 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4931 | } |
| 4932 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4933 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4934 | LocationSummary* locations = |
| 4935 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4936 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4940 | HBasicBlock* block = instruction->GetBlock(); |
| 4941 | if (block->GetLoopInformation() != nullptr) { |
| 4942 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4943 | // The back edge will generate the suspend check. |
| 4944 | return; |
| 4945 | } |
| 4946 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4947 | // The goto will generate the suspend check. |
| 4948 | return; |
| 4949 | } |
| 4950 | GenerateSuspendCheck(instruction, nullptr); |
| 4951 | } |
| 4952 | |
| 4953 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4954 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4955 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4956 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 4957 | if (slow_path == nullptr) { |
| 4958 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 4959 | instruction->SetSlowPath(slow_path); |
| 4960 | codegen_->AddSlowPath(slow_path); |
| 4961 | if (successor != nullptr) { |
| 4962 | DCHECK(successor->IsLoopHeader()); |
| 4963 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4964 | } |
| 4965 | } else { |
| 4966 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4967 | } |
| 4968 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4969 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4970 | /* no_rip */ true), |
| 4971 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4972 | if (successor == nullptr) { |
| 4973 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4974 | __ Bind(slow_path->GetReturnLabel()); |
| 4975 | } else { |
| 4976 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4977 | __ jmp(slow_path->GetEntryLabel()); |
| 4978 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4979 | } |
| 4980 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4981 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 4982 | return codegen_->GetAssembler(); |
| 4983 | } |
| 4984 | |
| 4985 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4986 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4987 | Location source = move->GetSource(); |
| 4988 | Location destination = move->GetDestination(); |
| 4989 | |
| 4990 | if (source.IsRegister()) { |
| 4991 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4992 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4993 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4994 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4995 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4996 | } else { |
| 4997 | DCHECK(destination.IsDoubleStackSlot()); |
| 4998 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4999 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5000 | } |
| 5001 | } else if (source.IsStackSlot()) { |
| 5002 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5003 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5004 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5005 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5006 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5007 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5008 | } else { |
| 5009 | DCHECK(destination.IsStackSlot()); |
| 5010 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5011 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5012 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5013 | } else if (source.IsDoubleStackSlot()) { |
| 5014 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5015 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5016 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5017 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5018 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5019 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5020 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5021 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5022 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5023 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5024 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5025 | } else if (source.IsConstant()) { |
| 5026 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5027 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5028 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5029 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5030 | if (value == 0) { |
| 5031 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5032 | } else { |
| 5033 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5034 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5035 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5036 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5037 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5038 | } |
| 5039 | } else if (constant->IsLongConstant()) { |
| 5040 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5041 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5042 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5043 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5044 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5045 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5046 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5047 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5048 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5049 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5050 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5051 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5052 | } else { |
| 5053 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5054 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5055 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5056 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5057 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5058 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5059 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5060 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5061 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5062 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5063 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5064 | } else { |
| 5065 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5066 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5067 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5068 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5069 | } else if (source.IsFpuRegister()) { |
| 5070 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5071 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5072 | } else if (destination.IsStackSlot()) { |
| 5073 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5074 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5075 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5076 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5077 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5078 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5079 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5080 | } |
| 5081 | } |
| 5082 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5083 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5084 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5085 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5086 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5087 | } |
| 5088 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5089 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5090 | ScratchRegisterScope ensure_scratch( |
| 5091 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5092 | |
| 5093 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5094 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5095 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5096 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5097 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5098 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5099 | CpuRegister(ensure_scratch.GetRegister())); |
| 5100 | } |
| 5101 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5102 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5103 | __ movq(CpuRegister(TMP), reg1); |
| 5104 | __ movq(reg1, reg2); |
| 5105 | __ movq(reg2, CpuRegister(TMP)); |
| 5106 | } |
| 5107 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5108 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5109 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5110 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5111 | __ movq(reg, CpuRegister(TMP)); |
| 5112 | } |
| 5113 | |
| 5114 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5115 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5116 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5117 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5118 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5119 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5120 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5121 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5122 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5123 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5124 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5125 | } |
| 5126 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5127 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5128 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5129 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5130 | __ movd(reg, CpuRegister(TMP)); |
| 5131 | } |
| 5132 | |
| 5133 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5134 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5135 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5136 | __ movd(reg, CpuRegister(TMP)); |
| 5137 | } |
| 5138 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5139 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5140 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5141 | Location source = move->GetSource(); |
| 5142 | Location destination = move->GetDestination(); |
| 5143 | |
| 5144 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5145 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5146 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5147 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5148 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5149 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5150 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5151 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5152 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5153 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5154 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5155 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5156 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5157 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5158 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5159 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5160 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5161 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5162 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5163 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5164 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5165 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5166 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5167 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5168 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5169 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5170 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5171 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5172 | } |
| 5173 | } |
| 5174 | |
| 5175 | |
| 5176 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5177 | __ pushq(CpuRegister(reg)); |
| 5178 | } |
| 5179 | |
| 5180 | |
| 5181 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5182 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5183 | } |
| 5184 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5185 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5186 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5187 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5188 | Immediate(mirror::Class::kStatusInitialized)); |
| 5189 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5190 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5191 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5192 | } |
| 5193 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5194 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5195 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5196 | switch (desired_class_load_kind) { |
| 5197 | case HLoadClass::LoadKind::kReferrersClass: |
| 5198 | break; |
| 5199 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5200 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5201 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5202 | return HLoadClass::LoadKind::kBootImageLinkTimePcRelative; |
| 5203 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5204 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5205 | break; |
| 5206 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5207 | break; |
| 5208 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5209 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5210 | break; |
| 5211 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5212 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5213 | break; |
| 5214 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5215 | break; |
| 5216 | } |
| 5217 | return desired_class_load_kind; |
| 5218 | } |
| 5219 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5220 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5221 | if (cls->NeedsAccessCheck()) { |
| 5222 | InvokeRuntimeCallingConvention calling_convention; |
| 5223 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5224 | cls, |
| 5225 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5226 | Location::RegisterLocation(RAX), |
| 5227 | /* code_generator_supports_read_barrier */ true); |
| 5228 | return; |
| 5229 | } |
| 5230 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5231 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5232 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5233 | ? LocationSummary::kCallOnSlowPath |
| 5234 | : LocationSummary::kNoCall; |
| 5235 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5236 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5237 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5238 | } |
| 5239 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5240 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5241 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5242 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5243 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5244 | } |
| 5245 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5249 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5250 | if (cls->NeedsAccessCheck()) { |
| 5251 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5252 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5253 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5254 | return; |
| 5255 | } |
| 5256 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5257 | Location out_loc = locations->Out(); |
| 5258 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5259 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5260 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5261 | bool generate_null_check = false; |
| 5262 | switch (cls->GetLoadKind()) { |
| 5263 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5264 | DCHECK(!cls->CanCallRuntime()); |
| 5265 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5266 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5267 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5268 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5269 | cls, |
| 5270 | out_loc, |
| 5271 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| 5272 | /*fixup_label*/nullptr, |
| 5273 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5274 | break; |
| 5275 | } |
| 5276 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5277 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5278 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5279 | codegen_->RecordTypePatch(cls); |
| 5280 | break; |
| 5281 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5282 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5283 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5284 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5285 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5286 | codegen_->RecordSimplePatch(); |
| 5287 | break; |
| 5288 | } |
| 5289 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5290 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5291 | // /* GcRoot<mirror::Class> */ out = *address |
| 5292 | if (IsUint<32>(cls->GetAddress())) { |
| 5293 | Address address = Address::Absolute(cls->GetAddress(), /* no_rip */ true); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5294 | GenerateGcRootFieldLoad(cls, |
| 5295 | out_loc, |
| 5296 | address, |
| 5297 | /*fixup_label*/nullptr, |
| 5298 | requires_read_barrier); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5299 | } else { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5300 | // TODO: Consider using opcode A1, i.e. movl eax, moff32 (with 64-bit address). |
| 5301 | __ movq(out, Immediate(cls->GetAddress())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5302 | GenerateGcRootFieldLoad(cls, |
| 5303 | out_loc, |
| 5304 | Address(out, 0), |
| 5305 | /*fixup_label*/nullptr, |
| 5306 | requires_read_barrier); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5307 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5308 | generate_null_check = !cls->IsInDexCache(); |
| 5309 | break; |
| 5310 | } |
| 5311 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5312 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 5313 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 5314 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5315 | /* no_rip */ false); |
| 5316 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5317 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5318 | generate_null_check = !cls->IsInDexCache(); |
| 5319 | break; |
| 5320 | } |
| 5321 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5322 | // /* GcRoot<mirror::Class>[] */ out = |
| 5323 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5324 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5325 | __ movq(out, |
| 5326 | Address(current_method, |
| 5327 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
| 5328 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5329 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5330 | cls, |
| 5331 | out_loc, |
| 5332 | Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())), |
| 5333 | /*fixup_label*/nullptr, |
| 5334 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5335 | generate_null_check = !cls->IsInDexCache(); |
| 5336 | break; |
| 5337 | } |
| 5338 | default: |
| 5339 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5340 | UNREACHABLE(); |
| 5341 | } |
| 5342 | |
| 5343 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5344 | DCHECK(cls->CanCallRuntime()); |
| 5345 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5346 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5347 | codegen_->AddSlowPath(slow_path); |
| 5348 | if (generate_null_check) { |
| 5349 | __ testl(out, out); |
| 5350 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5351 | } |
| 5352 | if (cls->MustGenerateClinitCheck()) { |
| 5353 | GenerateClassInitializationCheck(slow_path, out); |
| 5354 | } else { |
| 5355 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5356 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5357 | } |
| 5358 | } |
| 5359 | |
| 5360 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5361 | LocationSummary* locations = |
| 5362 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5363 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5364 | if (check->HasUses()) { |
| 5365 | locations->SetOut(Location::SameAsFirstInput()); |
| 5366 | } |
| 5367 | } |
| 5368 | |
| 5369 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5370 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5371 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5372 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5373 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5374 | GenerateClassInitializationCheck(slow_path, |
| 5375 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5376 | } |
| 5377 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5378 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5379 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5380 | switch (desired_string_load_kind) { |
| 5381 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5382 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5383 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5384 | return HLoadString::LoadKind::kBootImageLinkTimePcRelative; |
| 5385 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5386 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5387 | break; |
| 5388 | case HLoadString::LoadKind::kBootImageAddress: |
| 5389 | break; |
| 5390 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5391 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5392 | break; |
| 5393 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5394 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5395 | break; |
| 5396 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5397 | break; |
| 5398 | } |
| 5399 | return desired_string_load_kind; |
| 5400 | } |
| 5401 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5402 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5403 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
| 5404 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5405 | : LocationSummary::kNoCall; |
| 5406 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5407 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 5408 | locations->SetInAt(0, Location::RequiresRegister()); |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5409 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 5410 | } else { |
| 5411 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5412 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5413 | } |
| 5414 | |
| 5415 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5416 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5417 | Location out_loc = locations->Out(); |
| 5418 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5419 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5420 | switch (load->GetLoadKind()) { |
| 5421 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5422 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5423 | codegen_->RecordStringPatch(load); |
| 5424 | return; // No dex cache slow path. |
| 5425 | } |
| 5426 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5427 | DCHECK_NE(load->GetAddress(), 0u); |
| 5428 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5429 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5430 | codegen_->RecordSimplePatch(); |
| 5431 | return; // No dex cache slow path. |
| 5432 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5433 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5434 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5435 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5436 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5437 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5438 | InvokeRuntimeCallingConvention calling_convention; |
| 5439 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 5440 | Immediate(load->GetStringIndex())); |
| 5441 | codegen_->InvokeRuntime(kQuickResolveString, |
| 5442 | load, |
| 5443 | load->GetDexPc()); |
| 5444 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5445 | } |
| 5446 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5447 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5448 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5449 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5450 | } |
| 5451 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5452 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5453 | LocationSummary* locations = |
| 5454 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5455 | locations->SetOut(Location::RequiresRegister()); |
| 5456 | } |
| 5457 | |
| 5458 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5459 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5460 | } |
| 5461 | |
| 5462 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5463 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5464 | } |
| 5465 | |
| 5466 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5467 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5468 | } |
| 5469 | |
| 5470 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5471 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5472 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5473 | InvokeRuntimeCallingConvention calling_convention; |
| 5474 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5475 | } |
| 5476 | |
| 5477 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5478 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5479 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5480 | } |
| 5481 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5482 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5483 | return kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5484 | !kUseBakerReadBarrier && |
| 5485 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5486 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5487 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5488 | } |
| 5489 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5490 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5491 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5492 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5493 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5494 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5495 | case TypeCheckKind::kExactCheck: |
| 5496 | case TypeCheckKind::kAbstractClassCheck: |
| 5497 | case TypeCheckKind::kClassHierarchyCheck: |
| 5498 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5499 | call_kind = |
| 5500 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5501 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5502 | break; |
| 5503 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5504 | case TypeCheckKind::kUnresolvedCheck: |
| 5505 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5506 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5507 | break; |
| 5508 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5509 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5510 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5511 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5512 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5513 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5514 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5515 | locations->SetInAt(1, Location::Any()); |
| 5516 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5517 | locations->SetOut(Location::RequiresRegister()); |
| 5518 | // When read barriers are enabled, we need a temporary register for |
| 5519 | // some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5520 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5521 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5522 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5525 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5526 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5527 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5528 | Location obj_loc = locations->InAt(0); |
| 5529 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5530 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5531 | Location out_loc = locations->Out(); |
| 5532 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5533 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5534 | locations->GetTemp(0) : |
| 5535 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5536 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5537 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5538 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5539 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5540 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5541 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5542 | |
| 5543 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5544 | // Avoid null check if we know obj is not null. |
| 5545 | if (instruction->MustDoNullCheck()) { |
| 5546 | __ testl(obj, obj); |
| 5547 | __ j(kEqual, &zero); |
| 5548 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5549 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5550 | // /* HeapReference<Class> */ out = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5551 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5552 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5553 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5554 | case TypeCheckKind::kExactCheck: { |
| 5555 | if (cls.IsRegister()) { |
| 5556 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5557 | } else { |
| 5558 | DCHECK(cls.IsStackSlot()) << cls; |
| 5559 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5560 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5561 | if (zero.IsLinked()) { |
| 5562 | // Classes must be equal for the instanceof to succeed. |
| 5563 | __ j(kNotEqual, &zero); |
| 5564 | __ movl(out, Immediate(1)); |
| 5565 | __ jmp(&done); |
| 5566 | } else { |
| 5567 | __ setcc(kEqual, out); |
| 5568 | // setcc only sets the low byte. |
| 5569 | __ andl(out, Immediate(1)); |
| 5570 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5571 | break; |
| 5572 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5573 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5574 | case TypeCheckKind::kAbstractClassCheck: { |
| 5575 | // If the class is abstract, we eagerly fetch the super class of the |
| 5576 | // object to avoid doing a comparison we know will fail. |
| 5577 | NearLabel loop, success; |
| 5578 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5579 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5580 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5581 | __ testl(out, out); |
| 5582 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5583 | __ j(kEqual, &done); |
| 5584 | if (cls.IsRegister()) { |
| 5585 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5586 | } else { |
| 5587 | DCHECK(cls.IsStackSlot()) << cls; |
| 5588 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5589 | } |
| 5590 | __ j(kNotEqual, &loop); |
| 5591 | __ movl(out, Immediate(1)); |
| 5592 | if (zero.IsLinked()) { |
| 5593 | __ jmp(&done); |
| 5594 | } |
| 5595 | break; |
| 5596 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5597 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5598 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5599 | // Walk over the class hierarchy to find a match. |
| 5600 | NearLabel loop, success; |
| 5601 | __ Bind(&loop); |
| 5602 | if (cls.IsRegister()) { |
| 5603 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5604 | } else { |
| 5605 | DCHECK(cls.IsStackSlot()) << cls; |
| 5606 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5607 | } |
| 5608 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5609 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5610 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5611 | __ testl(out, out); |
| 5612 | __ j(kNotEqual, &loop); |
| 5613 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5614 | __ jmp(&done); |
| 5615 | __ Bind(&success); |
| 5616 | __ movl(out, Immediate(1)); |
| 5617 | if (zero.IsLinked()) { |
| 5618 | __ jmp(&done); |
| 5619 | } |
| 5620 | break; |
| 5621 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5622 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5623 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5624 | // Do an exact check. |
| 5625 | NearLabel exact_check; |
| 5626 | if (cls.IsRegister()) { |
| 5627 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5628 | } else { |
| 5629 | DCHECK(cls.IsStackSlot()) << cls; |
| 5630 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5631 | } |
| 5632 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5633 | // 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] | 5634 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5635 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5636 | __ testl(out, out); |
| 5637 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5638 | __ j(kEqual, &done); |
| 5639 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5640 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5641 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5642 | __ movl(out, Immediate(1)); |
| 5643 | __ jmp(&done); |
| 5644 | break; |
| 5645 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5646 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5647 | case TypeCheckKind::kArrayCheck: { |
| 5648 | if (cls.IsRegister()) { |
| 5649 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5650 | } else { |
| 5651 | DCHECK(cls.IsStackSlot()) << cls; |
| 5652 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5653 | } |
| 5654 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5655 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5656 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5657 | codegen_->AddSlowPath(slow_path); |
| 5658 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5659 | __ movl(out, Immediate(1)); |
| 5660 | if (zero.IsLinked()) { |
| 5661 | __ jmp(&done); |
| 5662 | } |
| 5663 | break; |
| 5664 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5665 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5666 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5667 | case TypeCheckKind::kInterfaceCheck: { |
| 5668 | // 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] | 5669 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5670 | // cases. |
| 5671 | // |
| 5672 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5673 | // entry point without resorting to a type checking slow path |
| 5674 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5675 | // require to assign fixed registers for the inputs of this |
| 5676 | // HInstanceOf instruction (following the runtime calling |
| 5677 | // convention), which might be cluttered by the potential first |
| 5678 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5679 | // |
| 5680 | // TODO: Introduce a new runtime entry point taking the object |
| 5681 | // to test (instead of its class) as argument, and let it deal |
| 5682 | // with the read barrier issues. This will let us refactor this |
| 5683 | // case of the `switch` code as it was previously (with a direct |
| 5684 | // call to the runtime not using a type checking slow path). |
| 5685 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5686 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5687 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5688 | /* is_fatal */ false); |
| 5689 | codegen_->AddSlowPath(slow_path); |
| 5690 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5691 | if (zero.IsLinked()) { |
| 5692 | __ jmp(&done); |
| 5693 | } |
| 5694 | break; |
| 5695 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5696 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5697 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5698 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5699 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5700 | __ xorl(out, out); |
| 5701 | } |
| 5702 | |
| 5703 | if (done.IsLinked()) { |
| 5704 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5705 | } |
| 5706 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5707 | if (slow_path != nullptr) { |
| 5708 | __ Bind(slow_path->GetExitLabel()); |
| 5709 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5710 | } |
| 5711 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5712 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5713 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5714 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5715 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5716 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5717 | case TypeCheckKind::kExactCheck: |
| 5718 | case TypeCheckKind::kAbstractClassCheck: |
| 5719 | case TypeCheckKind::kClassHierarchyCheck: |
| 5720 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5721 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5722 | LocationSummary::kCallOnSlowPath : |
| 5723 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5724 | break; |
| 5725 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5726 | case TypeCheckKind::kUnresolvedCheck: |
| 5727 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5728 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5729 | break; |
| 5730 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5731 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5732 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5733 | locations->SetInAt(1, Location::Any()); |
| 5734 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 5735 | locations->AddTemp(Location::RequiresRegister()); |
| 5736 | // When read barriers are enabled, we need an additional temporary |
| 5737 | // register for some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5738 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5739 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5740 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5744 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5745 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5746 | Location obj_loc = locations->InAt(0); |
| 5747 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5748 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5749 | Location temp_loc = locations->GetTemp(0); |
| 5750 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5751 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5752 | locations->GetTemp(1) : |
| 5753 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5754 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5755 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5756 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5757 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5758 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5759 | bool is_type_check_slow_path_fatal = |
| 5760 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5761 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5762 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5763 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5764 | !instruction->CanThrowIntoCatchBlock(); |
| 5765 | SlowPathCode* type_check_slow_path = |
| 5766 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5767 | is_type_check_slow_path_fatal); |
| 5768 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5769 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5770 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5771 | case TypeCheckKind::kExactCheck: |
| 5772 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5773 | NearLabel done; |
| 5774 | // Avoid null check if we know obj is not null. |
| 5775 | if (instruction->MustDoNullCheck()) { |
| 5776 | __ testl(obj, obj); |
| 5777 | __ j(kEqual, &done); |
| 5778 | } |
| 5779 | |
| 5780 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5781 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5782 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5783 | if (cls.IsRegister()) { |
| 5784 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5785 | } else { |
| 5786 | DCHECK(cls.IsStackSlot()) << cls; |
| 5787 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5788 | } |
| 5789 | // Jump to slow path for throwing the exception or doing a |
| 5790 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5791 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5792 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5793 | break; |
| 5794 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5795 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5796 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5797 | NearLabel done; |
| 5798 | // Avoid null check if we know obj is not null. |
| 5799 | if (instruction->MustDoNullCheck()) { |
| 5800 | __ testl(obj, obj); |
| 5801 | __ j(kEqual, &done); |
| 5802 | } |
| 5803 | |
| 5804 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5805 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5806 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5807 | // If the class is abstract, we eagerly fetch the super class of the |
| 5808 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5809 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5810 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5811 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5812 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5813 | |
| 5814 | // If the class reference currently in `temp` is not null, jump |
| 5815 | // to the `compare_classes` label to compare it with the checked |
| 5816 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5817 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5818 | __ j(kNotEqual, &compare_classes); |
| 5819 | // Otherwise, jump to the slow path to throw the exception. |
| 5820 | // |
| 5821 | // But before, move back the object's class into `temp` before |
| 5822 | // going into the slow path, as it has been overwritten in the |
| 5823 | // meantime. |
| 5824 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5825 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5826 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5827 | |
| 5828 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5829 | if (cls.IsRegister()) { |
| 5830 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5831 | } else { |
| 5832 | DCHECK(cls.IsStackSlot()) << cls; |
| 5833 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5834 | } |
| 5835 | __ j(kNotEqual, &loop); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5836 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5837 | break; |
| 5838 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5839 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5840 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5841 | NearLabel done; |
| 5842 | // Avoid null check if we know obj is not null. |
| 5843 | if (instruction->MustDoNullCheck()) { |
| 5844 | __ testl(obj, obj); |
| 5845 | __ j(kEqual, &done); |
| 5846 | } |
| 5847 | |
| 5848 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5849 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5850 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5851 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5852 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5853 | __ Bind(&loop); |
| 5854 | if (cls.IsRegister()) { |
| 5855 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5856 | } else { |
| 5857 | DCHECK(cls.IsStackSlot()) << cls; |
| 5858 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5859 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5860 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5861 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5862 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5863 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5864 | |
| 5865 | // If the class reference currently in `temp` is not null, jump |
| 5866 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5867 | __ testl(temp, temp); |
| 5868 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5869 | // Otherwise, jump to the slow path to throw the exception. |
| 5870 | // |
| 5871 | // But before, move back the object's class into `temp` before |
| 5872 | // going into the slow path, as it has been overwritten in the |
| 5873 | // meantime. |
| 5874 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5875 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5876 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5877 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5878 | break; |
| 5879 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5880 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5881 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5882 | // We cannot use a NearLabel here, as its range might be too |
| 5883 | // short in some cases when read barriers are enabled. This has |
| 5884 | // been observed for instance when the code emitted for this |
| 5885 | // case uses high x86-64 registers (R8-R15). |
| 5886 | Label done; |
| 5887 | // Avoid null check if we know obj is not null. |
| 5888 | if (instruction->MustDoNullCheck()) { |
| 5889 | __ testl(obj, obj); |
| 5890 | __ j(kEqual, &done); |
| 5891 | } |
| 5892 | |
| 5893 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5894 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5895 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5896 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5897 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5898 | if (cls.IsRegister()) { |
| 5899 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5900 | } else { |
| 5901 | DCHECK(cls.IsStackSlot()) << cls; |
| 5902 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5903 | } |
| 5904 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5905 | |
| 5906 | // 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] | 5907 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5908 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5909 | |
| 5910 | // If the component type is not null (i.e. the object is indeed |
| 5911 | // an array), jump to label `check_non_primitive_component_type` |
| 5912 | // to further check that this component type is not a primitive |
| 5913 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5914 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5915 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 5916 | // Otherwise, jump to the slow path to throw the exception. |
| 5917 | // |
| 5918 | // But before, move back the object's class into `temp` before |
| 5919 | // going into the slow path, as it has been overwritten in the |
| 5920 | // meantime. |
| 5921 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5922 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5923 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5924 | |
| 5925 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5926 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5927 | __ j(kEqual, &done); |
| 5928 | // Same comment as above regarding `temp` and the slow path. |
| 5929 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5930 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5931 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5932 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5933 | break; |
| 5934 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5935 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5936 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5937 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5938 | NearLabel done; |
| 5939 | // Avoid null check if we know obj is not null. |
| 5940 | if (instruction->MustDoNullCheck()) { |
| 5941 | __ testl(obj, obj); |
| 5942 | __ j(kEqual, &done); |
| 5943 | } |
| 5944 | |
| 5945 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5946 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5947 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5948 | // We always go into the type check slow path for the unresolved |
| 5949 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5950 | // |
| 5951 | // We cannot directly call the CheckCast runtime entry point |
| 5952 | // without resorting to a type checking slow path here (i.e. by |
| 5953 | // calling InvokeRuntime directly), as it would require to |
| 5954 | // assign fixed registers for the inputs of this HInstanceOf |
| 5955 | // instruction (following the runtime calling convention), which |
| 5956 | // might be cluttered by the potential first read barrier |
| 5957 | // emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5958 | // |
| 5959 | // TODO: Introduce a new runtime entry point taking the object |
| 5960 | // to test (instead of its class) as argument, and let it deal |
| 5961 | // with the read barrier issues. This will let us refactor this |
| 5962 | // case of the `switch` code as it was previously (with a direct |
| 5963 | // call to the runtime not using a type checking slow path). |
| 5964 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5965 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5966 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5967 | break; |
| 5968 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5969 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5970 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5971 | } |
| 5972 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5973 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5974 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5975 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5976 | InvokeRuntimeCallingConvention calling_convention; |
| 5977 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5978 | } |
| 5979 | |
| 5980 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5981 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5982 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5983 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5984 | if (instruction->IsEnter()) { |
| 5985 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5986 | } else { |
| 5987 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5988 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5989 | } |
| 5990 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5991 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5992 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5993 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5994 | |
| 5995 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5996 | LocationSummary* locations = |
| 5997 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5998 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5999 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6000 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6001 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6002 | locations->SetOut(Location::SameAsFirstInput()); |
| 6003 | } |
| 6004 | |
| 6005 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6006 | HandleBitwiseOperation(instruction); |
| 6007 | } |
| 6008 | |
| 6009 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6010 | HandleBitwiseOperation(instruction); |
| 6011 | } |
| 6012 | |
| 6013 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6014 | HandleBitwiseOperation(instruction); |
| 6015 | } |
| 6016 | |
| 6017 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6018 | LocationSummary* locations = instruction->GetLocations(); |
| 6019 | Location first = locations->InAt(0); |
| 6020 | Location second = locations->InAt(1); |
| 6021 | DCHECK(first.Equals(locations->Out())); |
| 6022 | |
| 6023 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6024 | if (second.IsRegister()) { |
| 6025 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6026 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6027 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6028 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6029 | } else { |
| 6030 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6031 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6032 | } |
| 6033 | } else if (second.IsConstant()) { |
| 6034 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6035 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6036 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6037 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6038 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6039 | } else { |
| 6040 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6041 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6042 | } |
| 6043 | } else { |
| 6044 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6045 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6046 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6047 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6048 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6049 | } else { |
| 6050 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6051 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6052 | } |
| 6053 | } |
| 6054 | } else { |
| 6055 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6056 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6057 | bool second_is_constant = false; |
| 6058 | int64_t value = 0; |
| 6059 | if (second.IsConstant()) { |
| 6060 | second_is_constant = true; |
| 6061 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6062 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6063 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6064 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6065 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6066 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6067 | if (is_int32_value) { |
| 6068 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6069 | } else { |
| 6070 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6071 | } |
| 6072 | } else if (second.IsDoubleStackSlot()) { |
| 6073 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6074 | } else { |
| 6075 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6076 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6077 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6078 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6079 | if (is_int32_value) { |
| 6080 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6081 | } else { |
| 6082 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6083 | } |
| 6084 | } else if (second.IsDoubleStackSlot()) { |
| 6085 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6086 | } else { |
| 6087 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6088 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6089 | } else { |
| 6090 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6091 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6092 | if (is_int32_value) { |
| 6093 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6094 | } else { |
| 6095 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6096 | } |
| 6097 | } else if (second.IsDoubleStackSlot()) { |
| 6098 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6099 | } else { |
| 6100 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6101 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6102 | } |
| 6103 | } |
| 6104 | } |
| 6105 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6106 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6107 | Location out, |
| 6108 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6109 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6110 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6111 | if (kEmitCompilerReadBarrier) { |
| 6112 | if (kUseBakerReadBarrier) { |
| 6113 | // Load with fast path based Baker's read barrier. |
| 6114 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6115 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6116 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6117 | } else { |
| 6118 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6119 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6120 | // in the following move operation, as we will need it for the |
| 6121 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6122 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6123 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6124 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6125 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6126 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6127 | } |
| 6128 | } else { |
| 6129 | // Plain load with no read barrier. |
| 6130 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6131 | __ movl(out_reg, Address(out_reg, offset)); |
| 6132 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6133 | } |
| 6134 | } |
| 6135 | |
| 6136 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6137 | Location out, |
| 6138 | Location obj, |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6139 | uint32_t offset) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6140 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6141 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| 6142 | if (kEmitCompilerReadBarrier) { |
| 6143 | if (kUseBakerReadBarrier) { |
| 6144 | // Load with fast path based Baker's read barrier. |
| 6145 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6146 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6147 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6148 | } else { |
| 6149 | // Load with slow path based read barrier. |
| 6150 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6151 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6152 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6153 | } |
| 6154 | } else { |
| 6155 | // Plain load with no read barrier. |
| 6156 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6157 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6158 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6159 | } |
| 6160 | } |
| 6161 | |
| 6162 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6163 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6164 | const Address& address, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6165 | Label* fixup_label, |
| 6166 | bool requires_read_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6167 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6168 | if (requires_read_barrier) { |
| 6169 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6170 | if (kUseBakerReadBarrier) { |
| 6171 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6172 | // Baker's read barrier are used: |
| 6173 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6174 | // root = *address; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6175 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6176 | // root = ReadBarrier::Mark(root) |
| 6177 | // } |
| 6178 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6179 | // /* GcRoot<mirror::Object> */ root = *address |
| 6180 | __ movl(root_reg, address); |
| 6181 | if (fixup_label != nullptr) { |
| 6182 | __ Bind(fixup_label); |
| 6183 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6184 | static_assert( |
| 6185 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6186 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6187 | "have different sizes."); |
| 6188 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6189 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6190 | "have different sizes."); |
| 6191 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6192 | // Slow path marking the GC root `root`. |
| 6193 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6194 | instruction, root, /* unpoison */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6195 | codegen_->AddSlowPath(slow_path); |
| 6196 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6197 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6198 | /* no_rip */ true), |
| 6199 | Immediate(0)); |
| 6200 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6201 | __ Bind(slow_path->GetExitLabel()); |
| 6202 | } else { |
| 6203 | // GC root loaded through a slow path for read barriers other |
| 6204 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6205 | // /* GcRoot<mirror::Object>* */ root = address |
| 6206 | __ leaq(root_reg, address); |
| 6207 | if (fixup_label != nullptr) { |
| 6208 | __ Bind(fixup_label); |
| 6209 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6210 | // /* mirror::Object* */ root = root->Read() |
| 6211 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6212 | } |
| 6213 | } else { |
| 6214 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6215 | // /* GcRoot<mirror::Object> */ root = *address |
| 6216 | __ movl(root_reg, address); |
| 6217 | if (fixup_label != nullptr) { |
| 6218 | __ Bind(fixup_label); |
| 6219 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6220 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6221 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6222 | } |
| 6223 | } |
| 6224 | |
| 6225 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6226 | Location ref, |
| 6227 | CpuRegister obj, |
| 6228 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6229 | bool needs_null_check) { |
| 6230 | DCHECK(kEmitCompilerReadBarrier); |
| 6231 | DCHECK(kUseBakerReadBarrier); |
| 6232 | |
| 6233 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6234 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6235 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6236 | } |
| 6237 | |
| 6238 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6239 | Location ref, |
| 6240 | CpuRegister obj, |
| 6241 | uint32_t data_offset, |
| 6242 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6243 | bool needs_null_check) { |
| 6244 | DCHECK(kEmitCompilerReadBarrier); |
| 6245 | DCHECK(kUseBakerReadBarrier); |
| 6246 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6247 | static_assert( |
| 6248 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6249 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6250 | // /* HeapReference<Object> */ ref = |
| 6251 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6252 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6253 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6254 | } |
| 6255 | |
| 6256 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6257 | Location ref, |
| 6258 | CpuRegister obj, |
| 6259 | const Address& src, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6260 | bool needs_null_check) { |
| 6261 | DCHECK(kEmitCompilerReadBarrier); |
| 6262 | DCHECK(kUseBakerReadBarrier); |
| 6263 | |
| 6264 | // In slow path based read barriers, the read barrier call is |
| 6265 | // inserted after the original load. However, in fast path based |
| 6266 | // Baker's read barriers, we need to perform the load of |
| 6267 | // mirror::Object::monitor_ *before* the original reference load. |
| 6268 | // This load-load ordering is required by the read barrier. |
| 6269 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6270 | // |
| 6271 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6272 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6273 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6274 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6275 | // if (is_gray) { |
| 6276 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6277 | // } |
| 6278 | // |
| 6279 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6280 | // slightly more complex as: |
| 6281 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6282 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6283 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6284 | // 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] | 6285 | // - it performs additional checks that we do not do here for |
| 6286 | // performance reasons. |
| 6287 | |
| 6288 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6289 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6290 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6291 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 6292 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6293 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6294 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6295 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6296 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6297 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6298 | |
| 6299 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6300 | // ref = ReadBarrier::Mark(ref); |
| 6301 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6302 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6303 | if (needs_null_check) { |
| 6304 | MaybeRecordImplicitNullCheck(instruction); |
| 6305 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6306 | |
| 6307 | // Load fence to prevent load-load reordering. |
| 6308 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6309 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6310 | |
| 6311 | // The actual reference load. |
| 6312 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6313 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6314 | |
| 6315 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6316 | // Slow path marking the object `ref` when it is gray. |
| 6317 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6318 | instruction, ref, /* unpoison */ true); |
| 6319 | AddSlowPath(slow_path); |
| 6320 | |
| 6321 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6322 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6323 | |
| 6324 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6325 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6326 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6327 | __ Bind(slow_path->GetExitLabel()); |
| 6328 | } |
| 6329 | |
| 6330 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6331 | Location out, |
| 6332 | Location ref, |
| 6333 | Location obj, |
| 6334 | uint32_t offset, |
| 6335 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6336 | DCHECK(kEmitCompilerReadBarrier); |
| 6337 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6338 | // Insert a slow path based read barrier *after* the reference load. |
| 6339 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6340 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6341 | // reference will be carried out by the runtime within the slow |
| 6342 | // path. |
| 6343 | // |
| 6344 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6345 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6346 | // not used by the artReadBarrierSlow entry point. |
| 6347 | // |
| 6348 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6349 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6350 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6351 | AddSlowPath(slow_path); |
| 6352 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6353 | __ jmp(slow_path->GetEntryLabel()); |
| 6354 | __ Bind(slow_path->GetExitLabel()); |
| 6355 | } |
| 6356 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6357 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6358 | Location out, |
| 6359 | Location ref, |
| 6360 | Location obj, |
| 6361 | uint32_t offset, |
| 6362 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6363 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6364 | // Baker's read barriers shall be handled by the fast path |
| 6365 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6366 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6367 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6368 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6369 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6370 | } else if (kPoisonHeapReferences) { |
| 6371 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6372 | } |
| 6373 | } |
| 6374 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6375 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6376 | Location out, |
| 6377 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6378 | DCHECK(kEmitCompilerReadBarrier); |
| 6379 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6380 | // Insert a slow path based read barrier *after* the GC root load. |
| 6381 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6382 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6383 | // not need to do anything special for this here. |
| 6384 | SlowPathCode* slow_path = |
| 6385 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6386 | AddSlowPath(slow_path); |
| 6387 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6388 | __ jmp(slow_path->GetEntryLabel()); |
| 6389 | __ Bind(slow_path->GetExitLabel()); |
| 6390 | } |
| 6391 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6392 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6393 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6394 | LOG(FATAL) << "Unreachable"; |
| 6395 | } |
| 6396 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6397 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6398 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6399 | LOG(FATAL) << "Unreachable"; |
| 6400 | } |
| 6401 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6402 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6403 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6404 | LocationSummary* locations = |
| 6405 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6406 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6407 | locations->AddTemp(Location::RequiresRegister()); |
| 6408 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6409 | } |
| 6410 | |
| 6411 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6412 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6413 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6414 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6415 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6416 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6417 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6418 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6419 | |
| 6420 | // Should we generate smaller inline compare/jumps? |
| 6421 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6422 | // Figure out the correct compare values and jump conditions. |
| 6423 | // Handle the first compare/branch as a special case because it might |
| 6424 | // jump to the default case. |
| 6425 | DCHECK_GT(num_entries, 2u); |
| 6426 | Condition first_condition; |
| 6427 | uint32_t index; |
| 6428 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6429 | if (lower_bound != 0) { |
| 6430 | first_condition = kLess; |
| 6431 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6432 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6433 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6434 | |
| 6435 | index = 1; |
| 6436 | } else { |
| 6437 | // Handle all the compare/jumps below. |
| 6438 | first_condition = kBelow; |
| 6439 | index = 0; |
| 6440 | } |
| 6441 | |
| 6442 | // Handle the rest of the compare/jumps. |
| 6443 | for (; index + 1 < num_entries; index += 2) { |
| 6444 | int32_t compare_to_value = lower_bound + index + 1; |
| 6445 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6446 | // Jump to successors[index] if value < case_value[index]. |
| 6447 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6448 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6449 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6450 | } |
| 6451 | |
| 6452 | if (index != num_entries) { |
| 6453 | // There are an odd number of entries. Handle the last one. |
| 6454 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6455 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6456 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6457 | } |
| 6458 | |
| 6459 | // And the default for any other value. |
| 6460 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6461 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6462 | } |
| 6463 | return; |
| 6464 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6465 | |
| 6466 | // Remove the bias, if needed. |
| 6467 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6468 | if (lower_bound != 0) { |
| 6469 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6470 | value_reg_out = temp_reg.AsRegister(); |
| 6471 | } |
| 6472 | CpuRegister value_reg(value_reg_out); |
| 6473 | |
| 6474 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6475 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6476 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6477 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6478 | // We are in the range of the table. |
| 6479 | // Load the address of the jump table in the constant area. |
| 6480 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6481 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6482 | // Load the (signed) offset from the jump table. |
| 6483 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6484 | |
| 6485 | // Add the offset to the address of the table base. |
| 6486 | __ addq(temp_reg, base_reg); |
| 6487 | |
| 6488 | // And jump. |
| 6489 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6490 | } |
| 6491 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6492 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6493 | if (value == 0) { |
| 6494 | __ xorl(dest, dest); |
| 6495 | } else { |
| 6496 | __ movl(dest, Immediate(value)); |
| 6497 | } |
| 6498 | } |
| 6499 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6500 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6501 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6502 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6503 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6504 | } else if (IsUint<32>(value)) { |
| 6505 | // 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] | 6506 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6507 | } else { |
| 6508 | __ movq(dest, Immediate(value)); |
| 6509 | } |
| 6510 | } |
| 6511 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6512 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6513 | if (value == 0) { |
| 6514 | __ xorps(dest, dest); |
| 6515 | } else { |
| 6516 | __ movss(dest, LiteralInt32Address(value)); |
| 6517 | } |
| 6518 | } |
| 6519 | |
| 6520 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6521 | if (value == 0) { |
| 6522 | __ xorpd(dest, dest); |
| 6523 | } else { |
| 6524 | __ movsd(dest, LiteralInt64Address(value)); |
| 6525 | } |
| 6526 | } |
| 6527 | |
| 6528 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6529 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6530 | } |
| 6531 | |
| 6532 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6533 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6534 | } |
| 6535 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6536 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6537 | if (value == 0) { |
| 6538 | __ testl(dest, dest); |
| 6539 | } else { |
| 6540 | __ cmpl(dest, Immediate(value)); |
| 6541 | } |
| 6542 | } |
| 6543 | |
| 6544 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6545 | if (IsInt<32>(value)) { |
| 6546 | if (value == 0) { |
| 6547 | __ testq(dest, dest); |
| 6548 | } else { |
| 6549 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6550 | } |
| 6551 | } else { |
| 6552 | // Value won't fit in an int. |
| 6553 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6554 | } |
| 6555 | } |
| 6556 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6557 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 6558 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame^] | 6559 | GenerateIntCompare(lhs_reg, rhs); |
| 6560 | } |
| 6561 | |
| 6562 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6563 | if (rhs.IsConstant()) { |
| 6564 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame^] | 6565 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6566 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame^] | 6567 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6568 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame^] | 6569 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6570 | } |
| 6571 | } |
| 6572 | |
| 6573 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 6574 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 6575 | if (rhs.IsConstant()) { |
| 6576 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 6577 | Compare64BitValue(lhs_reg, value); |
| 6578 | } else if (rhs.IsDoubleStackSlot()) { |
| 6579 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 6580 | } else { |
| 6581 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 6582 | } |
| 6583 | } |
| 6584 | |
| 6585 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 6586 | Location index, |
| 6587 | ScaleFactor scale, |
| 6588 | uint32_t data_offset) { |
| 6589 | return index.IsConstant() ? |
| 6590 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 6591 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 6592 | } |
| 6593 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6594 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6595 | DCHECK(dest.IsDoubleStackSlot()); |
| 6596 | if (IsInt<32>(value)) { |
| 6597 | // Can move directly as an int32 constant. |
| 6598 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6599 | Immediate(static_cast<int32_t>(value))); |
| 6600 | } else { |
| 6601 | Load64BitValue(CpuRegister(TMP), value); |
| 6602 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6603 | } |
| 6604 | } |
| 6605 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6606 | /** |
| 6607 | * Class to handle late fixup of offsets into constant area. |
| 6608 | */ |
| 6609 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6610 | public: |
| 6611 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6612 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6613 | |
| 6614 | protected: |
| 6615 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6616 | |
| 6617 | CodeGeneratorX86_64* codegen_; |
| 6618 | |
| 6619 | private: |
| 6620 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6621 | // Patch the correct offset for the instruction. We use the address of the |
| 6622 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6623 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6624 | int32_t relative_position = constant_offset - pos; |
| 6625 | |
| 6626 | // Patch in the right value. |
| 6627 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6628 | } |
| 6629 | |
| 6630 | // Location in constant area that the fixup refers to. |
| 6631 | size_t offset_into_constant_area_; |
| 6632 | }; |
| 6633 | |
| 6634 | /** |
| 6635 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6636 | * constant area. |
| 6637 | */ |
| 6638 | class JumpTableRIPFixup : public RIPFixup { |
| 6639 | public: |
| 6640 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6641 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6642 | |
| 6643 | void CreateJumpTable() { |
| 6644 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6645 | |
| 6646 | // Ensure that the reference to the jump table has the correct offset. |
| 6647 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6648 | SetOffset(offset_in_constant_table); |
| 6649 | |
| 6650 | // Compute the offset from the start of the function to this jump table. |
| 6651 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6652 | |
| 6653 | // Populate the jump table with the correct values for the jump table. |
| 6654 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6655 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6656 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6657 | // The value that we want is the target offset - the position of the table. |
| 6658 | for (int32_t i = 0; i < num_entries; i++) { |
| 6659 | HBasicBlock* b = successors[i]; |
| 6660 | Label* l = codegen_->GetLabelOf(b); |
| 6661 | DCHECK(l->IsBound()); |
| 6662 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 6663 | assembler->AppendInt32(offset_to_block); |
| 6664 | } |
| 6665 | } |
| 6666 | |
| 6667 | private: |
| 6668 | const HPackedSwitch* switch_instr_; |
| 6669 | }; |
| 6670 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6671 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 6672 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6673 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6674 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6675 | // 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] | 6676 | assembler->Align(4, 0); |
| 6677 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6678 | |
| 6679 | // Populate any jump tables. |
| 6680 | for (auto jump_table : fixups_to_jump_tables_) { |
| 6681 | jump_table->CreateJumpTable(); |
| 6682 | } |
| 6683 | |
| 6684 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6685 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6686 | } |
| 6687 | |
| 6688 | // And finish up. |
| 6689 | CodeGenerator::Finalize(allocator); |
| 6690 | } |
| 6691 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6692 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 6693 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 6694 | return Address::RIP(fixup); |
| 6695 | } |
| 6696 | |
| 6697 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 6698 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 6699 | return Address::RIP(fixup); |
| 6700 | } |
| 6701 | |
| 6702 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 6703 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 6704 | return Address::RIP(fixup); |
| 6705 | } |
| 6706 | |
| 6707 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 6708 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 6709 | return Address::RIP(fixup); |
| 6710 | } |
| 6711 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6712 | // TODO: trg as memory. |
| 6713 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6714 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6715 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6716 | return; |
| 6717 | } |
| 6718 | |
| 6719 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6720 | |
| 6721 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 6722 | if (trg.Equals(return_loc)) { |
| 6723 | return; |
| 6724 | } |
| 6725 | |
| 6726 | // Let the parallel move resolver take care of all of this. |
| 6727 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6728 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6729 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6730 | } |
| 6731 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6732 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 6733 | // Create a fixup to be used to create and address the jump table. |
| 6734 | JumpTableRIPFixup* table_fixup = |
| 6735 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 6736 | |
| 6737 | // We have to populate the jump tables. |
| 6738 | fixups_to_jump_tables_.push_back(table_fixup); |
| 6739 | return Address::RIP(table_fixup); |
| 6740 | } |
| 6741 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 6742 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 6743 | const Address& addr_high, |
| 6744 | int64_t v, |
| 6745 | HInstruction* instruction) { |
| 6746 | if (IsInt<32>(v)) { |
| 6747 | int32_t v_32 = v; |
| 6748 | __ movq(addr_low, Immediate(v_32)); |
| 6749 | MaybeRecordImplicitNullCheck(instruction); |
| 6750 | } else { |
| 6751 | // Didn't fit in a register. Do it in pieces. |
| 6752 | int32_t low_v = Low32Bits(v); |
| 6753 | int32_t high_v = High32Bits(v); |
| 6754 | __ movl(addr_low, Immediate(low_v)); |
| 6755 | MaybeRecordImplicitNullCheck(instruction); |
| 6756 | __ movl(addr_high, Immediate(high_v)); |
| 6757 | } |
| 6758 | } |
| 6759 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6760 | #undef __ |
| 6761 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6762 | } // namespace x86_64 |
| 6763 | } // namespace art |