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); |
| 201 | } |
| 202 | |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 203 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 204 | // move resolver. |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 205 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 206 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 207 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 208 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 209 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 210 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 211 | Primitive::kPrimInt); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 212 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 213 | ? kQuickThrowStringBounds |
| 214 | : kQuickThrowArrayBounds; |
| 215 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 216 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 217 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 218 | } |
| 219 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 220 | bool IsFatal() const OVERRIDE { return true; } |
| 221 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 222 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 223 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 224 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 225 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 226 | }; |
| 227 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 228 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 229 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 230 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 231 | HInstruction* at, |
| 232 | uint32_t dex_pc, |
| 233 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 234 | : 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] | 235 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 236 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 237 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 238 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 239 | LocationSummary* locations = at_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 240 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 241 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 242 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 243 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 245 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 246 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 247 | x86_64_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage : kQuickInitializeType, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 248 | at_, |
| 249 | dex_pc_, |
| 250 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 251 | if (do_clinit_) { |
| 252 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 253 | } else { |
| 254 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 255 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 256 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 257 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 258 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 259 | if (out.IsValid()) { |
| 260 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 261 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 264 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 265 | __ jmp(GetExitLabel()); |
| 266 | } |
| 267 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 268 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 269 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 270 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | // The class this slow path will load. |
| 272 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 273 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 274 | // The instruction where this slow path is happening. |
| 275 | // (Might be the load class or an initialization check). |
| 276 | HInstruction* const at_; |
| 277 | |
| 278 | // The dex PC of `at_`. |
| 279 | const uint32_t dex_pc_; |
| 280 | |
| 281 | // Whether to initialize the class. |
| 282 | const bool do_clinit_; |
| 283 | |
| 284 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 285 | }; |
| 286 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 287 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 288 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 289 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 290 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 291 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 292 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 293 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 294 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 295 | : locations->Out(); |
| 296 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 297 | DCHECK(instruction_->IsCheckCast() |
| 298 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 299 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 300 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 301 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 302 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 303 | if (!is_fatal_) { |
| 304 | SaveLiveRegisters(codegen, locations); |
| 305 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 306 | |
| 307 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 308 | // move resolver. |
| 309 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 310 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 311 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 312 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 313 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 314 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 315 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 316 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 318 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 319 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 320 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 321 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 322 | } else { |
| 323 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 324 | x86_64_codegen->InvokeRuntime(kQuickCheckCast, instruction_, dex_pc, this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 325 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 326 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 327 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 328 | if (!is_fatal_) { |
| 329 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 330 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 331 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 332 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 333 | RestoreLiveRegisters(codegen, locations); |
| 334 | __ jmp(GetExitLabel()); |
| 335 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 338 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 339 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 340 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 341 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 342 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 343 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 344 | |
| 345 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 346 | }; |
| 347 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 348 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 349 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 350 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 351 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 352 | |
| 353 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 354 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 355 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 356 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 357 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 360 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 361 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 362 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 363 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 364 | }; |
| 365 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 366 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 367 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 368 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 369 | |
| 370 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 371 | LocationSummary* locations = instruction_->GetLocations(); |
| 372 | __ Bind(GetEntryLabel()); |
| 373 | SaveLiveRegisters(codegen, locations); |
| 374 | |
| 375 | InvokeRuntimeCallingConvention calling_convention; |
| 376 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 377 | parallel_move.AddMove( |
| 378 | locations->InAt(0), |
| 379 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 380 | Primitive::kPrimNot, |
| 381 | nullptr); |
| 382 | parallel_move.AddMove( |
| 383 | locations->InAt(1), |
| 384 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 385 | Primitive::kPrimInt, |
| 386 | nullptr); |
| 387 | parallel_move.AddMove( |
| 388 | locations->InAt(2), |
| 389 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 390 | Primitive::kPrimNot, |
| 391 | nullptr); |
| 392 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 393 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 394 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 395 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 396 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 397 | RestoreLiveRegisters(codegen, locations); |
| 398 | __ jmp(GetExitLabel()); |
| 399 | } |
| 400 | |
| 401 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 402 | |
| 403 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 404 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 405 | }; |
| 406 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 407 | // Slow path marking an object during a read barrier. |
| 408 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 409 | public: |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 410 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, Location obj, bool unpoison) |
| 411 | : SlowPathCode(instruction), obj_(obj), unpoison_(unpoison) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 412 | DCHECK(kEmitCompilerReadBarrier); |
| 413 | } |
| 414 | |
| 415 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 416 | |
| 417 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 418 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 419 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 420 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 421 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 422 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 423 | instruction_->IsStaticFieldGet() || |
| 424 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 425 | instruction_->IsArraySet() || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 426 | instruction_->IsLoadClass() || |
| 427 | instruction_->IsLoadString() || |
| 428 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 429 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 430 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 431 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 432 | << "Unexpected instruction in read barrier marking slow path: " |
| 433 | << instruction_->DebugName(); |
| 434 | |
| 435 | __ Bind(GetEntryLabel()); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 436 | if (unpoison_) { |
| 437 | // Object* ref = ref_addr->AsMirrorPtr() |
| 438 | __ MaybeUnpoisonHeapReference(obj_.AsRegister<CpuRegister>()); |
| 439 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 440 | // No need to save live registers; it's taken care of by the |
| 441 | // entrypoint. Also, there is no need to update the stack mask, |
| 442 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 443 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 444 | DCHECK_NE(reg, RSP); |
| 445 | DCHECK(0 <= reg && reg < kNumberOfCpuRegisters) << reg; |
| 446 | // "Compact" slow path, saving two moves. |
| 447 | // |
| 448 | // Instead of using the standard runtime calling convention (input |
| 449 | // and output in R0): |
| 450 | // |
| 451 | // RDI <- obj |
| 452 | // RAX <- ReadBarrierMark(RDI) |
| 453 | // obj <- RAX |
| 454 | // |
| 455 | // we just use rX (the register holding `obj`) as input and output |
| 456 | // of a dedicated entrypoint: |
| 457 | // |
| 458 | // rX <- ReadBarrierMarkRegX(rX) |
| 459 | // |
| 460 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 461 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 462 | // This runtime call does not require a stack map. |
| 463 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 464 | __ jmp(GetExitLabel()); |
| 465 | } |
| 466 | |
| 467 | private: |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 468 | const Location obj_; |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 469 | const bool unpoison_; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 470 | |
| 471 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 472 | }; |
| 473 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 474 | // Slow path generating a read barrier for a heap reference. |
| 475 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 476 | public: |
| 477 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 478 | Location out, |
| 479 | Location ref, |
| 480 | Location obj, |
| 481 | uint32_t offset, |
| 482 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 483 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 484 | out_(out), |
| 485 | ref_(ref), |
| 486 | obj_(obj), |
| 487 | offset_(offset), |
| 488 | index_(index) { |
| 489 | DCHECK(kEmitCompilerReadBarrier); |
| 490 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 491 | // object has been overwritten by (or after) the heap object |
| 492 | // reference load to be instrumented, e.g.: |
| 493 | // |
| 494 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 495 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 496 | // |
| 497 | // In that case, we have lost the information about the original |
| 498 | // object, and the emitted read barrier cannot work properly. |
| 499 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 500 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 501 | } |
| 502 | |
| 503 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 504 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 505 | LocationSummary* locations = instruction_->GetLocations(); |
| 506 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 507 | DCHECK(locations->CanCall()); |
| 508 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 509 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 510 | instruction_->IsStaticFieldGet() || |
| 511 | instruction_->IsArrayGet() || |
| 512 | instruction_->IsInstanceOf() || |
| 513 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 514 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 515 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 516 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 517 | |
| 518 | __ Bind(GetEntryLabel()); |
| 519 | SaveLiveRegisters(codegen, locations); |
| 520 | |
| 521 | // We may have to change the index's value, but as `index_` is a |
| 522 | // constant member (like other "inputs" of this slow path), |
| 523 | // introduce a copy of it, `index`. |
| 524 | Location index = index_; |
| 525 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 526 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 527 | if (instruction_->IsArrayGet()) { |
| 528 | // Compute real offset and store it in index_. |
| 529 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 530 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 531 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 532 | // We are about to change the value of `index_reg` (see the |
| 533 | // calls to art::x86_64::X86_64Assembler::shll and |
| 534 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 535 | // has not been saved by the previous call to |
| 536 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 537 | // callee-save register -- |
| 538 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 539 | // callee-save registers, as it has been designed with the |
| 540 | // assumption that callee-save registers are supposed to be |
| 541 | // handled by the called function. So, as a callee-save |
| 542 | // register, `index_reg` _would_ eventually be saved onto |
| 543 | // the stack, but it would be too late: we would have |
| 544 | // changed its value earlier. Therefore, we manually save |
| 545 | // it here into another freely available register, |
| 546 | // `free_reg`, chosen of course among the caller-save |
| 547 | // registers (as a callee-save `free_reg` register would |
| 548 | // exhibit the same problem). |
| 549 | // |
| 550 | // Note we could have requested a temporary register from |
| 551 | // the register allocator instead; but we prefer not to, as |
| 552 | // this is a slow path, and we know we can find a |
| 553 | // caller-save register that is available. |
| 554 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 555 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 556 | index_reg = free_reg; |
| 557 | index = Location::RegisterLocation(index_reg); |
| 558 | } else { |
| 559 | // The initial register stored in `index_` has already been |
| 560 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 561 | // (as it is not a callee-save register), so we can freely |
| 562 | // use it. |
| 563 | } |
| 564 | // Shifting the index value contained in `index_reg` by the |
| 565 | // scale factor (2) cannot overflow in practice, as the |
| 566 | // runtime is unable to allocate object arrays with a size |
| 567 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 568 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 569 | static_assert( |
| 570 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 571 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 572 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 573 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 574 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 575 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 576 | // (as in the case of ArrayGet), as it is actually an offset |
| 577 | // to an object field within an object. |
| 578 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 579 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 580 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 581 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 582 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 583 | DCHECK_EQ(offset_, 0U); |
| 584 | DCHECK(index_.IsRegister()); |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | // We're moving two or three locations to locations that could |
| 589 | // overlap, so we need a parallel move resolver. |
| 590 | InvokeRuntimeCallingConvention calling_convention; |
| 591 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 592 | parallel_move.AddMove(ref_, |
| 593 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 594 | Primitive::kPrimNot, |
| 595 | nullptr); |
| 596 | parallel_move.AddMove(obj_, |
| 597 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 598 | Primitive::kPrimNot, |
| 599 | nullptr); |
| 600 | if (index.IsValid()) { |
| 601 | parallel_move.AddMove(index, |
| 602 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 603 | Primitive::kPrimInt, |
| 604 | nullptr); |
| 605 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 606 | } else { |
| 607 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 608 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 609 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 610 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 611 | instruction_, |
| 612 | instruction_->GetDexPc(), |
| 613 | this); |
| 614 | CheckEntrypointTypes< |
| 615 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 616 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 617 | |
| 618 | RestoreLiveRegisters(codegen, locations); |
| 619 | __ jmp(GetExitLabel()); |
| 620 | } |
| 621 | |
| 622 | const char* GetDescription() const OVERRIDE { |
| 623 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 624 | } |
| 625 | |
| 626 | private: |
| 627 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 628 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 629 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 630 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 631 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 632 | return static_cast<CpuRegister>(i); |
| 633 | } |
| 634 | } |
| 635 | // We shall never fail to find a free caller-save register, as |
| 636 | // there are more than two core caller-save registers on x86-64 |
| 637 | // (meaning it is possible to find one which is different from |
| 638 | // `ref` and `obj`). |
| 639 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 640 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 641 | UNREACHABLE(); |
| 642 | } |
| 643 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 644 | const Location out_; |
| 645 | const Location ref_; |
| 646 | const Location obj_; |
| 647 | const uint32_t offset_; |
| 648 | // An additional location containing an index to an array. |
| 649 | // Only used for HArrayGet and the UnsafeGetObject & |
| 650 | // UnsafeGetObjectVolatile intrinsics. |
| 651 | const Location index_; |
| 652 | |
| 653 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 654 | }; |
| 655 | |
| 656 | // Slow path generating a read barrier for a GC root. |
| 657 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 658 | public: |
| 659 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 660 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 661 | DCHECK(kEmitCompilerReadBarrier); |
| 662 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 663 | |
| 664 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 665 | LocationSummary* locations = instruction_->GetLocations(); |
| 666 | DCHECK(locations->CanCall()); |
| 667 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 668 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 669 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 670 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 671 | |
| 672 | __ Bind(GetEntryLabel()); |
| 673 | SaveLiveRegisters(codegen, locations); |
| 674 | |
| 675 | InvokeRuntimeCallingConvention calling_convention; |
| 676 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 677 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 678 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 679 | instruction_, |
| 680 | instruction_->GetDexPc(), |
| 681 | this); |
| 682 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 683 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 684 | |
| 685 | RestoreLiveRegisters(codegen, locations); |
| 686 | __ jmp(GetExitLabel()); |
| 687 | } |
| 688 | |
| 689 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 690 | |
| 691 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 692 | const Location out_; |
| 693 | const Location root_; |
| 694 | |
| 695 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 696 | }; |
| 697 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 698 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 699 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 700 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 701 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 702 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 703 | switch (cond) { |
| 704 | case kCondEQ: return kEqual; |
| 705 | case kCondNE: return kNotEqual; |
| 706 | case kCondLT: return kLess; |
| 707 | case kCondLE: return kLessEqual; |
| 708 | case kCondGT: return kGreater; |
| 709 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 710 | case kCondB: return kBelow; |
| 711 | case kCondBE: return kBelowEqual; |
| 712 | case kCondA: return kAbove; |
| 713 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 714 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 715 | LOG(FATAL) << "Unreachable"; |
| 716 | UNREACHABLE(); |
| 717 | } |
| 718 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 719 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 720 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 721 | switch (cond) { |
| 722 | case kCondEQ: return kEqual; |
| 723 | case kCondNE: return kNotEqual; |
| 724 | case kCondLT: return kBelow; |
| 725 | case kCondLE: return kBelowEqual; |
| 726 | case kCondGT: return kAbove; |
| 727 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 728 | default: break; // should not happen |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 729 | }; |
| 730 | LOG(FATAL) << "Unreachable"; |
| 731 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 734 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 735 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 736 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 737 | switch (desired_dispatch_info.code_ptr_location) { |
| 738 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 739 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 740 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 741 | return HInvokeStaticOrDirect::DispatchInfo { |
| 742 | desired_dispatch_info.method_load_kind, |
| 743 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 744 | desired_dispatch_info.method_load_data, |
| 745 | 0u |
| 746 | }; |
| 747 | default: |
| 748 | return desired_dispatch_info; |
| 749 | } |
| 750 | } |
| 751 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 752 | Location CodeGeneratorX86_64::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 753 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 754 | // All registers are assumed to be correctly set up. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 755 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 756 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame^] | 757 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 758 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame^] | 759 | uint32_t offset = |
| 760 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 761 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 762 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame^] | 763 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 764 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 765 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 766 | break; |
| 767 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 768 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 769 | break; |
| 770 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 771 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 772 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 773 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 774 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 775 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 776 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 777 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 778 | // Bind a new fixup label at the end of the "movl" insn. |
| 779 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 780 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFile(), offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 781 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 782 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 783 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 784 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 785 | Register method_reg; |
| 786 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 787 | if (current_method.IsRegister()) { |
| 788 | method_reg = current_method.AsRegister<Register>(); |
| 789 | } else { |
| 790 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 791 | DCHECK(!current_method.IsValid()); |
| 792 | method_reg = reg.AsRegister(); |
| 793 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 794 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 795 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 796 | __ movq(reg, |
| 797 | Address(CpuRegister(method_reg), |
| 798 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 799 | // temp = temp[index_in_cache]; |
| 800 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 801 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 802 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 803 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 804 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 805 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 806 | return callee_method; |
| 807 | } |
| 808 | |
| 809 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 810 | Location temp) { |
| 811 | // All registers are assumed to be correctly set up. |
| 812 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 813 | |
| 814 | switch (invoke->GetCodePtrLocation()) { |
| 815 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 816 | __ call(&frame_entry_label_); |
| 817 | break; |
| 818 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 819 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 820 | Label* label = &relative_call_patches_.back().label; |
| 821 | __ call(label); // Bind to the patch label, override at link time. |
| 822 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 823 | break; |
| 824 | } |
| 825 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 826 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 827 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 828 | LOG(FATAL) << "Unsupported"; |
| 829 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 830 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 831 | // (callee_method + offset_of_quick_compiled_code)() |
| 832 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 833 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 834 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 835 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 836 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 837 | |
| 838 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 839 | } |
| 840 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 841 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 842 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 843 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 844 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 845 | |
| 846 | // Use the calling convention instead of the location of the receiver, as |
| 847 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 848 | // slow path, the arguments have been moved to the right place, so here we are |
| 849 | // guaranteed that the receiver is the first register of the calling convention. |
| 850 | InvokeDexCallingConvention calling_convention; |
| 851 | Register receiver = calling_convention.GetRegisterAt(0); |
| 852 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 853 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 854 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 855 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 856 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 857 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 858 | // emit a read barrier for the previous class reference load. |
| 859 | // However this is not required in practice, as this is an |
| 860 | // intermediate/temporary reference and because the current |
| 861 | // concurrent copying collector keeps the from-space memory |
| 862 | // intact/accessible until the end of the marking phase (the |
| 863 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 864 | __ MaybeUnpoisonHeapReference(temp); |
| 865 | // temp = temp->GetMethodAt(method_offset); |
| 866 | __ movq(temp, Address(temp, method_offset)); |
| 867 | // call temp->GetEntryPoint(); |
| 868 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 869 | kX86_64PointerSize).SizeValue())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 870 | } |
| 871 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 872 | void CodeGeneratorX86_64::RecordSimplePatch() { |
| 873 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 874 | simple_patches_.emplace_back(); |
| 875 | __ Bind(&simple_patches_.back()); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | void CodeGeneratorX86_64::RecordStringPatch(HLoadString* load_string) { |
| 880 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 881 | __ Bind(&string_patches_.back().label); |
| 882 | } |
| 883 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 884 | void CodeGeneratorX86_64::RecordTypePatch(HLoadClass* load_class) { |
| 885 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 886 | __ Bind(&type_patches_.back().label); |
| 887 | } |
| 888 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 889 | Label* CodeGeneratorX86_64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 890 | uint32_t element_offset) { |
| 891 | // Add a patch entry and return the label. |
| 892 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 893 | return &pc_relative_dex_cache_patches_.back().label; |
| 894 | } |
| 895 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 896 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 897 | DCHECK(linker_patches->empty()); |
| 898 | size_t size = |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 899 | method_patches_.size() + |
| 900 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 901 | pc_relative_dex_cache_patches_.size() + |
| 902 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 903 | string_patches_.size() + |
| 904 | type_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 905 | linker_patches->reserve(size); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 906 | // The label points to the end of the "movl" insn but the literal offset for method |
| 907 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 908 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 909 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 910 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 911 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 912 | info.target_method.dex_file, |
| 913 | info.target_method.dex_method_index)); |
| 914 | } |
| 915 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 916 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 917 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 918 | info.target_method.dex_file, |
| 919 | info.target_method.dex_method_index)); |
| 920 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 921 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 922 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 923 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 924 | &info.target_dex_file, |
| 925 | info.label.Position(), |
| 926 | info.element_offset)); |
| 927 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 928 | for (const Label& label : simple_patches_) { |
| 929 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 930 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 931 | } |
| 932 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 933 | // These are always PC-relative, see GetSupportedLoadStringKind(). |
| 934 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 935 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 936 | &info.dex_file, |
| 937 | info.label.Position(), |
| 938 | info.string_index)); |
| 939 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 940 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 941 | // These are always PC-relative, see GetSupportedLoadClassKind(). |
| 942 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 943 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(literal_offset, |
| 944 | &info.dex_file, |
| 945 | info.label.Position(), |
| 946 | info.type_index)); |
| 947 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 948 | } |
| 949 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 950 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 951 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 955 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 956 | } |
| 957 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 958 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 959 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 960 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 961 | } |
| 962 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 963 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 964 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 965 | return kX86_64WordSize; |
| 966 | } |
| 967 | |
| 968 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 969 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 970 | return kX86_64WordSize; |
| 971 | } |
| 972 | |
| 973 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 974 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 975 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 976 | } |
| 977 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 978 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 979 | HInstruction* instruction, |
| 980 | uint32_t dex_pc, |
| 981 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 982 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 983 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 984 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 985 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 986 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 987 | } |
| 988 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 989 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 990 | HInstruction* instruction, |
| 991 | SlowPathCode* slow_path) { |
| 992 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 993 | GenerateInvokeRuntime(entry_point_offset); |
| 994 | } |
| 995 | |
| 996 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 997 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
| 998 | } |
| 999 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1000 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1001 | // Use a fake return address register to mimic Quick. |
| 1002 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1003 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1004 | const X86_64InstructionSetFeatures& isa_features, |
| 1005 | const CompilerOptions& compiler_options, |
| 1006 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1007 | : CodeGenerator(graph, |
| 1008 | kNumberOfCpuRegisters, |
| 1009 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1010 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1011 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1012 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1013 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1014 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1015 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1016 | compiler_options, |
| 1017 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1018 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1019 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1020 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1021 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1022 | assembler_(graph->GetArena()), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1023 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1024 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1025 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1026 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1027 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1028 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1029 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1030 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 1031 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1032 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1033 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1034 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1035 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1036 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1037 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1038 | assembler_(codegen->GetAssembler()), |
| 1039 | codegen_(codegen) {} |
| 1040 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1041 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1042 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1043 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1044 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1045 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1046 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1047 | } |
| 1048 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1049 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1050 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1051 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1052 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1053 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1054 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1055 | } |
| 1056 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1057 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1058 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1059 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1060 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1061 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1062 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1063 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1064 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1065 | __ testq(CpuRegister(RAX), Address( |
| 1066 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1067 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1068 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1069 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1070 | if (HasEmptyFrame()) { |
| 1071 | return; |
| 1072 | } |
| 1073 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1074 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1075 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1076 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1077 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1078 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1079 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1080 | } |
| 1081 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1082 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1083 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1084 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1085 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1086 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1087 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1088 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1089 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1090 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1091 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1092 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1093 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1094 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1095 | } |
| 1096 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1097 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1098 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1102 | __ cfi().RememberState(); |
| 1103 | if (!HasEmptyFrame()) { |
| 1104 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1105 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1106 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1107 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1108 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1109 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1110 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1115 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1116 | __ cfi().AdjustCFAOffset(-adjust); |
| 1117 | |
| 1118 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1119 | Register reg = kCoreCalleeSaves[i]; |
| 1120 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1121 | __ popq(CpuRegister(reg)); |
| 1122 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1123 | __ cfi().Restore(DWARFReg(reg)); |
| 1124 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1125 | } |
| 1126 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1127 | __ ret(); |
| 1128 | __ cfi().RestoreState(); |
| 1129 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1130 | } |
| 1131 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1132 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1133 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1134 | } |
| 1135 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1136 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1137 | if (source.Equals(destination)) { |
| 1138 | return; |
| 1139 | } |
| 1140 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1141 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1142 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1143 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1144 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1145 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1146 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1147 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1148 | } else if (source.IsConstant()) { |
| 1149 | HConstant* constant = source.GetConstant(); |
| 1150 | if (constant->IsLongConstant()) { |
| 1151 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1152 | } else { |
| 1153 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1154 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1155 | } else { |
| 1156 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1157 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1158 | } |
| 1159 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1160 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1161 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1162 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1163 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1164 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1165 | } else if (source.IsConstant()) { |
| 1166 | HConstant* constant = source.GetConstant(); |
| 1167 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1168 | if (constant->IsFloatConstant()) { |
| 1169 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1170 | } else { |
| 1171 | Load64BitValue(dest, value); |
| 1172 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1173 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1174 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1175 | } else { |
| 1176 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1177 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1178 | } |
| 1179 | } else if (destination.IsStackSlot()) { |
| 1180 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1181 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1182 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1183 | } else if (source.IsFpuRegister()) { |
| 1184 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1185 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1186 | } else if (source.IsConstant()) { |
| 1187 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1188 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1189 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1190 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1191 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1192 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1193 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1194 | } |
| 1195 | } else { |
| 1196 | DCHECK(destination.IsDoubleStackSlot()); |
| 1197 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1198 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1199 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1200 | } else if (source.IsFpuRegister()) { |
| 1201 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1202 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1203 | } else if (source.IsConstant()) { |
| 1204 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1205 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1206 | int64_t value = GetInt64ValueOf(constant); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1207 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1208 | } else { |
| 1209 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1210 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1211 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | } |
| 1215 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1216 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1217 | DCHECK(location.IsRegister()); |
| 1218 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1219 | } |
| 1220 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1221 | void CodeGeneratorX86_64::MoveLocation( |
| 1222 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1223 | Move(dst, src); |
| 1224 | } |
| 1225 | |
| 1226 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1227 | if (location.IsRegister()) { |
| 1228 | locations->AddTemp(location); |
| 1229 | } else { |
| 1230 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1231 | } |
| 1232 | } |
| 1233 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1234 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1235 | DCHECK(!successor->IsExitBlock()); |
| 1236 | |
| 1237 | HBasicBlock* block = got->GetBlock(); |
| 1238 | HInstruction* previous = got->GetPrevious(); |
| 1239 | |
| 1240 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1241 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1242 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1243 | return; |
| 1244 | } |
| 1245 | |
| 1246 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1247 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1248 | } |
| 1249 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1250 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1251 | } |
| 1252 | } |
| 1253 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1254 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1255 | got->SetLocations(nullptr); |
| 1256 | } |
| 1257 | |
| 1258 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1259 | HandleGoto(got, got->GetSuccessor()); |
| 1260 | } |
| 1261 | |
| 1262 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1263 | try_boundary->SetLocations(nullptr); |
| 1264 | } |
| 1265 | |
| 1266 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1267 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1268 | if (!successor->IsExitBlock()) { |
| 1269 | HandleGoto(try_boundary, successor); |
| 1270 | } |
| 1271 | } |
| 1272 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1273 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1274 | exit->SetLocations(nullptr); |
| 1275 | } |
| 1276 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1277 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1278 | } |
| 1279 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1280 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1281 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1282 | LabelType* true_label, |
| 1283 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1284 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1285 | __ j(kUnordered, true_label); |
| 1286 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1287 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1288 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1289 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1290 | } |
| 1291 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1292 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1293 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1294 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1295 | Location left = locations->InAt(0); |
| 1296 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1297 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1298 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1299 | case Primitive::kPrimBoolean: |
| 1300 | case Primitive::kPrimByte: |
| 1301 | case Primitive::kPrimChar: |
| 1302 | case Primitive::kPrimShort: |
| 1303 | case Primitive::kPrimInt: |
| 1304 | case Primitive::kPrimNot: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1305 | codegen_->GenerateIntCompare(left, right); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1306 | break; |
| 1307 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1308 | case Primitive::kPrimLong: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1309 | codegen_->GenerateLongCompare(left, right); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1310 | break; |
| 1311 | } |
| 1312 | case Primitive::kPrimFloat: { |
| 1313 | if (right.IsFpuRegister()) { |
| 1314 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1315 | } else if (right.IsConstant()) { |
| 1316 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1317 | codegen_->LiteralFloatAddress( |
| 1318 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1319 | } else { |
| 1320 | DCHECK(right.IsStackSlot()); |
| 1321 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1322 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1323 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1324 | break; |
| 1325 | } |
| 1326 | case Primitive::kPrimDouble: { |
| 1327 | if (right.IsFpuRegister()) { |
| 1328 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1329 | } else if (right.IsConstant()) { |
| 1330 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1331 | codegen_->LiteralDoubleAddress( |
| 1332 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1333 | } else { |
| 1334 | DCHECK(right.IsDoubleStackSlot()); |
| 1335 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1336 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1337 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1338 | break; |
| 1339 | } |
| 1340 | default: |
| 1341 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | template<class LabelType> |
| 1346 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1347 | LabelType* true_target_in, |
| 1348 | LabelType* false_target_in) { |
| 1349 | // Generated branching requires both targets to be explicit. If either of the |
| 1350 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1351 | LabelType fallthrough_target; |
| 1352 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1353 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1354 | |
| 1355 | // Generate the comparison to set the CC. |
| 1356 | GenerateCompareTest(condition); |
| 1357 | |
| 1358 | // Now generate the correct jump(s). |
| 1359 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1360 | switch (type) { |
| 1361 | case Primitive::kPrimLong: { |
| 1362 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1363 | break; |
| 1364 | } |
| 1365 | case Primitive::kPrimFloat: { |
| 1366 | GenerateFPJumps(condition, true_target, false_target); |
| 1367 | break; |
| 1368 | } |
| 1369 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1370 | GenerateFPJumps(condition, true_target, false_target); |
| 1371 | break; |
| 1372 | } |
| 1373 | default: |
| 1374 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1375 | } |
| 1376 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1377 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1378 | __ jmp(false_target); |
| 1379 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1380 | |
| 1381 | if (fallthrough_target.IsLinked()) { |
| 1382 | __ Bind(&fallthrough_target); |
| 1383 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1384 | } |
| 1385 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1386 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1387 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1388 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1389 | // conditions if they are materialized due to the complex branching. |
| 1390 | return cond->IsCondition() && |
| 1391 | cond->GetNext() == branch && |
| 1392 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1393 | } |
| 1394 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1395 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1396 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1397 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1398 | LabelType* true_target, |
| 1399 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1400 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1401 | |
| 1402 | if (true_target == nullptr && false_target == nullptr) { |
| 1403 | // Nothing to do. The code always falls through. |
| 1404 | return; |
| 1405 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1406 | // Constant condition, statically compared against "true" (integer value 1). |
| 1407 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1408 | if (true_target != nullptr) { |
| 1409 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1410 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1411 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1412 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1413 | if (false_target != nullptr) { |
| 1414 | __ jmp(false_target); |
| 1415 | } |
| 1416 | } |
| 1417 | return; |
| 1418 | } |
| 1419 | |
| 1420 | // The following code generates these patterns: |
| 1421 | // (1) true_target == nullptr && false_target != nullptr |
| 1422 | // - opposite condition true => branch to false_target |
| 1423 | // (2) true_target != nullptr && false_target == nullptr |
| 1424 | // - condition true => branch to true_target |
| 1425 | // (3) true_target != nullptr && false_target != nullptr |
| 1426 | // - condition true => branch to true_target |
| 1427 | // - branch to false_target |
| 1428 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1429 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1430 | if (true_target == nullptr) { |
| 1431 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1432 | } else { |
| 1433 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1434 | } |
| 1435 | } else { |
| 1436 | // Materialized condition, compare against 0. |
| 1437 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1438 | if (lhs.IsRegister()) { |
| 1439 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1440 | } else { |
| 1441 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1442 | } |
| 1443 | if (true_target == nullptr) { |
| 1444 | __ j(kEqual, false_target); |
| 1445 | } else { |
| 1446 | __ j(kNotEqual, true_target); |
| 1447 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1448 | } |
| 1449 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1450 | // Condition has not been materialized, use its inputs as the |
| 1451 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1452 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1453 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1454 | // If this is a long or FP comparison that has been folded into |
| 1455 | // the HCondition, generate the comparison directly. |
| 1456 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1457 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1458 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1459 | return; |
| 1460 | } |
| 1461 | |
| 1462 | Location lhs = condition->GetLocations()->InAt(0); |
| 1463 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1464 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1465 | if (true_target == nullptr) { |
| 1466 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1467 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1468 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1469 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1470 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1471 | |
| 1472 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1473 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1474 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1475 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1476 | } |
| 1477 | } |
| 1478 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1479 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1480 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1481 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1482 | locations->SetInAt(0, Location::Any()); |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1487 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1488 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1489 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1490 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1491 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1492 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1493 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1497 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1498 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1499 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1500 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1501 | locations->SetInAt(0, Location::Any()); |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1506 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1507 | GenerateTestAndBranch<Label>(deoptimize, |
| 1508 | /* condition_input_index */ 0, |
| 1509 | slow_path->GetEntryLabel(), |
| 1510 | /* false_target */ nullptr); |
| 1511 | } |
| 1512 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1513 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1514 | // There are no conditional move instructions for XMMs. |
| 1515 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1516 | return false; |
| 1517 | } |
| 1518 | |
| 1519 | // A FP condition doesn't generate the single CC that we need. |
| 1520 | HInstruction* condition = select->GetCondition(); |
| 1521 | if (condition->IsCondition() && |
| 1522 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1523 | return false; |
| 1524 | } |
| 1525 | |
| 1526 | // We can generate a CMOV for this Select. |
| 1527 | return true; |
| 1528 | } |
| 1529 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1530 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1531 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1532 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1533 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1534 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1535 | } else { |
| 1536 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1537 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1538 | if (select->InputAt(1)->IsConstant()) { |
| 1539 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1540 | } else { |
| 1541 | locations->SetInAt(1, Location::Any()); |
| 1542 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1543 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1544 | locations->SetInAt(1, Location::Any()); |
| 1545 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1546 | } |
| 1547 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1548 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1549 | } |
| 1550 | locations->SetOut(Location::SameAsFirstInput()); |
| 1551 | } |
| 1552 | |
| 1553 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1554 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1555 | if (SelectCanUseCMOV(select)) { |
| 1556 | // If both the condition and the source types are integer, we can generate |
| 1557 | // a CMOV to implement Select. |
| 1558 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1559 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1560 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1561 | |
| 1562 | HInstruction* select_condition = select->GetCondition(); |
| 1563 | Condition cond = kNotEqual; |
| 1564 | |
| 1565 | // Figure out how to test the 'condition'. |
| 1566 | if (select_condition->IsCondition()) { |
| 1567 | HCondition* condition = select_condition->AsCondition(); |
| 1568 | if (!condition->IsEmittedAtUseSite()) { |
| 1569 | // This was a previously materialized condition. |
| 1570 | // Can we use the existing condition code? |
| 1571 | if (AreEflagsSetFrom(condition, select)) { |
| 1572 | // Materialization was the previous instruction. Condition codes are right. |
| 1573 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1574 | } else { |
| 1575 | // No, we have to recreate the condition code. |
| 1576 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1577 | __ testl(cond_reg, cond_reg); |
| 1578 | } |
| 1579 | } else { |
| 1580 | GenerateCompareTest(condition); |
| 1581 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1582 | } |
| 1583 | } else { |
| 1584 | // Must be a boolean condition, which needs to be compared to 0. |
| 1585 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1586 | __ testl(cond_reg, cond_reg); |
| 1587 | } |
| 1588 | |
| 1589 | // If the condition is true, overwrite the output, which already contains false. |
| 1590 | // Generate the correct sized CMOV. |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1591 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1592 | if (value_true_loc.IsRegister()) { |
| 1593 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1594 | } else { |
| 1595 | __ cmov(cond, |
| 1596 | value_false, |
| 1597 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1598 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1599 | } else { |
| 1600 | NearLabel false_target; |
| 1601 | GenerateTestAndBranch<NearLabel>(select, |
| 1602 | /* condition_input_index */ 2, |
| 1603 | /* true_target */ nullptr, |
| 1604 | &false_target); |
| 1605 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1606 | __ Bind(&false_target); |
| 1607 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1610 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1611 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1612 | } |
| 1613 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1614 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1615 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | void CodeGeneratorX86_64::GenerateNop() { |
| 1619 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1622 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1623 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1624 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1625 | // Handle the long/FP comparisons made in instruction simplification. |
| 1626 | switch (cond->InputAt(0)->GetType()) { |
| 1627 | case Primitive::kPrimLong: |
| 1628 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1629 | locations->SetInAt(1, Location::Any()); |
| 1630 | break; |
| 1631 | case Primitive::kPrimFloat: |
| 1632 | case Primitive::kPrimDouble: |
| 1633 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1634 | locations->SetInAt(1, Location::Any()); |
| 1635 | break; |
| 1636 | default: |
| 1637 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1638 | locations->SetInAt(1, Location::Any()); |
| 1639 | break; |
| 1640 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1641 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1642 | locations->SetOut(Location::RequiresRegister()); |
| 1643 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1644 | } |
| 1645 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1646 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1647 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1648 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1649 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1650 | |
| 1651 | LocationSummary* locations = cond->GetLocations(); |
| 1652 | Location lhs = locations->InAt(0); |
| 1653 | Location rhs = locations->InAt(1); |
| 1654 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1655 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1656 | |
| 1657 | switch (cond->InputAt(0)->GetType()) { |
| 1658 | default: |
| 1659 | // Integer case. |
| 1660 | |
| 1661 | // Clear output register: setcc only sets the low byte. |
| 1662 | __ xorl(reg, reg); |
| 1663 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1664 | codegen_->GenerateIntCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1665 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1666 | return; |
| 1667 | case Primitive::kPrimLong: |
| 1668 | // Clear output register: setcc only sets the low byte. |
| 1669 | __ xorl(reg, reg); |
| 1670 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1671 | codegen_->GenerateLongCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1672 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1673 | return; |
| 1674 | case Primitive::kPrimFloat: { |
| 1675 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1676 | if (rhs.IsConstant()) { |
| 1677 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1678 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1679 | } else if (rhs.IsStackSlot()) { |
| 1680 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1681 | } else { |
| 1682 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1683 | } |
| 1684 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1685 | break; |
| 1686 | } |
| 1687 | case Primitive::kPrimDouble: { |
| 1688 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1689 | if (rhs.IsConstant()) { |
| 1690 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1691 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1692 | } else if (rhs.IsDoubleStackSlot()) { |
| 1693 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1694 | } else { |
| 1695 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1696 | } |
| 1697 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1698 | break; |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1703 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1704 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1705 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1706 | __ Bind(&false_label); |
| 1707 | __ xorl(reg, reg); |
| 1708 | __ jmp(&done_label); |
| 1709 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1710 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1711 | __ Bind(&true_label); |
| 1712 | __ movl(reg, Immediate(1)); |
| 1713 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1717 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1721 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1725 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1729 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1733 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1737 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1741 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1745 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1749 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1753 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1757 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1761 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1762 | } |
| 1763 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1764 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1765 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1769 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1773 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1777 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1781 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1785 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1789 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1793 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1796 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1797 | LocationSummary* locations = |
| 1798 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1799 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1800 | case Primitive::kPrimBoolean: |
| 1801 | case Primitive::kPrimByte: |
| 1802 | case Primitive::kPrimShort: |
| 1803 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1804 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1805 | case Primitive::kPrimLong: { |
| 1806 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1807 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1808 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1809 | break; |
| 1810 | } |
| 1811 | case Primitive::kPrimFloat: |
| 1812 | case Primitive::kPrimDouble: { |
| 1813 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1814 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1815 | locations->SetOut(Location::RequiresRegister()); |
| 1816 | break; |
| 1817 | } |
| 1818 | default: |
| 1819 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1820 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1824 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1825 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1826 | Location left = locations->InAt(0); |
| 1827 | Location right = locations->InAt(1); |
| 1828 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1829 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1830 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1831 | Condition less_cond = kLess; |
| 1832 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1833 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1834 | case Primitive::kPrimBoolean: |
| 1835 | case Primitive::kPrimByte: |
| 1836 | case Primitive::kPrimShort: |
| 1837 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1838 | case Primitive::kPrimInt: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1839 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1840 | break; |
| 1841 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1842 | case Primitive::kPrimLong: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1843 | codegen_->GenerateLongCompare(left, right); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1844 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1845 | } |
| 1846 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1847 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1848 | if (right.IsConstant()) { |
| 1849 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1850 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1851 | } else if (right.IsStackSlot()) { |
| 1852 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1853 | } else { |
| 1854 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1855 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1856 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1857 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1858 | break; |
| 1859 | } |
| 1860 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1861 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1862 | if (right.IsConstant()) { |
| 1863 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1864 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1865 | } else if (right.IsDoubleStackSlot()) { |
| 1866 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1867 | } else { |
| 1868 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1869 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1870 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1871 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1872 | break; |
| 1873 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1874 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1875 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1876 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1877 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1878 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1879 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1880 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1881 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1882 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1883 | __ movl(out, Immediate(1)); |
| 1884 | __ jmp(&done); |
| 1885 | |
| 1886 | __ Bind(&less); |
| 1887 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1888 | |
| 1889 | __ Bind(&done); |
| 1890 | } |
| 1891 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1892 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1893 | LocationSummary* locations = |
| 1894 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1895 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1896 | } |
| 1897 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1898 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1899 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1900 | } |
| 1901 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1902 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1903 | LocationSummary* locations = |
| 1904 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1905 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1906 | } |
| 1907 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1908 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1909 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1910 | } |
| 1911 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1912 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1913 | LocationSummary* locations = |
| 1914 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1915 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1916 | } |
| 1917 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1918 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1919 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1920 | } |
| 1921 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1922 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1923 | LocationSummary* locations = |
| 1924 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1925 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1926 | } |
| 1927 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1928 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1929 | // Will be generated at use site. |
| 1930 | } |
| 1931 | |
| 1932 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1933 | LocationSummary* locations = |
| 1934 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1935 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1936 | } |
| 1937 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1938 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 1939 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1940 | // Will be generated at use site. |
| 1941 | } |
| 1942 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1943 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1944 | memory_barrier->SetLocations(nullptr); |
| 1945 | } |
| 1946 | |
| 1947 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 1948 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1949 | } |
| 1950 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1951 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1952 | ret->SetLocations(nullptr); |
| 1953 | } |
| 1954 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1955 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1956 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1960 | LocationSummary* locations = |
| 1961 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1962 | switch (ret->InputAt(0)->GetType()) { |
| 1963 | case Primitive::kPrimBoolean: |
| 1964 | case Primitive::kPrimByte: |
| 1965 | case Primitive::kPrimChar: |
| 1966 | case Primitive::kPrimShort: |
| 1967 | case Primitive::kPrimInt: |
| 1968 | case Primitive::kPrimNot: |
| 1969 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1970 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1971 | break; |
| 1972 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1973 | case Primitive::kPrimFloat: |
| 1974 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1975 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1976 | break; |
| 1977 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1978 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1979 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1980 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 1984 | if (kIsDebugBuild) { |
| 1985 | switch (ret->InputAt(0)->GetType()) { |
| 1986 | case Primitive::kPrimBoolean: |
| 1987 | case Primitive::kPrimByte: |
| 1988 | case Primitive::kPrimChar: |
| 1989 | case Primitive::kPrimShort: |
| 1990 | case Primitive::kPrimInt: |
| 1991 | case Primitive::kPrimNot: |
| 1992 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1993 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1994 | break; |
| 1995 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1996 | case Primitive::kPrimFloat: |
| 1997 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1998 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1999 | XMM0); |
| 2000 | break; |
| 2001 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2002 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2003 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2004 | } |
| 2005 | } |
| 2006 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2007 | } |
| 2008 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2009 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2010 | switch (type) { |
| 2011 | case Primitive::kPrimBoolean: |
| 2012 | case Primitive::kPrimByte: |
| 2013 | case Primitive::kPrimChar: |
| 2014 | case Primitive::kPrimShort: |
| 2015 | case Primitive::kPrimInt: |
| 2016 | case Primitive::kPrimNot: |
| 2017 | case Primitive::kPrimLong: |
| 2018 | return Location::RegisterLocation(RAX); |
| 2019 | |
| 2020 | case Primitive::kPrimVoid: |
| 2021 | return Location::NoLocation(); |
| 2022 | |
| 2023 | case Primitive::kPrimDouble: |
| 2024 | case Primitive::kPrimFloat: |
| 2025 | return Location::FpuRegisterLocation(XMM0); |
| 2026 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2027 | |
| 2028 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2032 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2033 | } |
| 2034 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2035 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2036 | switch (type) { |
| 2037 | case Primitive::kPrimBoolean: |
| 2038 | case Primitive::kPrimByte: |
| 2039 | case Primitive::kPrimChar: |
| 2040 | case Primitive::kPrimShort: |
| 2041 | case Primitive::kPrimInt: |
| 2042 | case Primitive::kPrimNot: { |
| 2043 | uint32_t index = gp_index_++; |
| 2044 | stack_index_++; |
| 2045 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2046 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2047 | } else { |
| 2048 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | case Primitive::kPrimLong: { |
| 2053 | uint32_t index = gp_index_; |
| 2054 | stack_index_ += 2; |
| 2055 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2056 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2057 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2058 | } else { |
| 2059 | gp_index_ += 2; |
| 2060 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2061 | } |
| 2062 | } |
| 2063 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2064 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2065 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2066 | stack_index_++; |
| 2067 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2068 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2069 | } else { |
| 2070 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2075 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2076 | stack_index_ += 2; |
| 2077 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2078 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2079 | } else { |
| 2080 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2081 | } |
| 2082 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2083 | |
| 2084 | case Primitive::kPrimVoid: |
| 2085 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2086 | break; |
| 2087 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2088 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2089 | } |
| 2090 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2091 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2092 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2093 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2094 | // the method_idx. |
| 2095 | HandleInvoke(invoke); |
| 2096 | } |
| 2097 | |
| 2098 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2099 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2100 | } |
| 2101 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2102 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2103 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2104 | // art::PrepareForRegisterAllocation. |
| 2105 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2106 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2107 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2108 | if (intrinsic.TryDispatch(invoke)) { |
| 2109 | return; |
| 2110 | } |
| 2111 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2112 | HandleInvoke(invoke); |
| 2113 | } |
| 2114 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2115 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2116 | if (invoke->GetLocations()->Intrinsified()) { |
| 2117 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2118 | intrinsic.Dispatch(invoke); |
| 2119 | return true; |
| 2120 | } |
| 2121 | return false; |
| 2122 | } |
| 2123 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2124 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2125 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2126 | // art::PrepareForRegisterAllocation. |
| 2127 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2128 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2129 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2130 | return; |
| 2131 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2132 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2133 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2134 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2135 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2136 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2137 | } |
| 2138 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2139 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2140 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2141 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2142 | } |
| 2143 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2144 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2145 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2146 | if (intrinsic.TryDispatch(invoke)) { |
| 2147 | return; |
| 2148 | } |
| 2149 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2150 | HandleInvoke(invoke); |
| 2151 | } |
| 2152 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2153 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2154 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2155 | return; |
| 2156 | } |
| 2157 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2158 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2159 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2160 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2161 | } |
| 2162 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2163 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2164 | HandleInvoke(invoke); |
| 2165 | // Add the hidden argument. |
| 2166 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2167 | } |
| 2168 | |
| 2169 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2170 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2171 | LocationSummary* locations = invoke->GetLocations(); |
| 2172 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2173 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2174 | Location receiver = locations->InAt(0); |
| 2175 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2176 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2177 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2178 | // won't be modified thereafter, before the `call` instruction. |
| 2179 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2180 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2181 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2182 | if (receiver.IsStackSlot()) { |
| 2183 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2184 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2185 | __ movl(temp, Address(temp, class_offset)); |
| 2186 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2187 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2188 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2189 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2190 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2191 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2192 | // emit a read barrier for the previous class reference load. |
| 2193 | // However this is not required in practice, as this is an |
| 2194 | // intermediate/temporary reference and because the current |
| 2195 | // concurrent copying collector keeps the from-space memory |
| 2196 | // intact/accessible until the end of the marking phase (the |
| 2197 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2198 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2199 | // temp = temp->GetAddressOfIMT() |
| 2200 | __ movq(temp, |
| 2201 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2202 | // temp = temp->GetImtEntryAt(method_offset); |
| 2203 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2204 | invoke->GetImtIndex(), kX86_64PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2205 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2206 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2207 | // call temp->GetEntryPoint(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2208 | __ call(Address( |
| 2209 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2210 | |
| 2211 | DCHECK(!codegen_->IsLeafMethod()); |
| 2212 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2213 | } |
| 2214 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2215 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2216 | LocationSummary* locations = |
| 2217 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2218 | switch (neg->GetResultType()) { |
| 2219 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2220 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2221 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2222 | locations->SetOut(Location::SameAsFirstInput()); |
| 2223 | break; |
| 2224 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2225 | case Primitive::kPrimFloat: |
| 2226 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2227 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2228 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2229 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2230 | break; |
| 2231 | |
| 2232 | default: |
| 2233 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2234 | } |
| 2235 | } |
| 2236 | |
| 2237 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2238 | LocationSummary* locations = neg->GetLocations(); |
| 2239 | Location out = locations->Out(); |
| 2240 | Location in = locations->InAt(0); |
| 2241 | switch (neg->GetResultType()) { |
| 2242 | case Primitive::kPrimInt: |
| 2243 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2244 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2245 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2246 | break; |
| 2247 | |
| 2248 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2249 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2250 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2251 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2252 | break; |
| 2253 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2254 | case Primitive::kPrimFloat: { |
| 2255 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2256 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2257 | // Implement float negation with an exclusive or with value |
| 2258 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2259 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2260 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2261 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2262 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2263 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2264 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2265 | case Primitive::kPrimDouble: { |
| 2266 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2267 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2268 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2269 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2270 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2271 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2272 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2273 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2274 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2275 | |
| 2276 | default: |
| 2277 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2278 | } |
| 2279 | } |
| 2280 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2281 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2282 | LocationSummary* locations = |
| 2283 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2284 | Primitive::Type result_type = conversion->GetResultType(); |
| 2285 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2286 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2287 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2288 | // The Java language does not allow treating boolean as an integral type but |
| 2289 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2290 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2291 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2292 | case Primitive::kPrimByte: |
| 2293 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2294 | case Primitive::kPrimLong: |
| 2295 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2296 | case Primitive::kPrimBoolean: |
| 2297 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2298 | case Primitive::kPrimShort: |
| 2299 | case Primitive::kPrimInt: |
| 2300 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2301 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2302 | locations->SetInAt(0, Location::Any()); |
| 2303 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2304 | break; |
| 2305 | |
| 2306 | default: |
| 2307 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2308 | << " to " << result_type; |
| 2309 | } |
| 2310 | break; |
| 2311 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimShort: |
| 2313 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2314 | case Primitive::kPrimLong: |
| 2315 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2316 | case Primitive::kPrimBoolean: |
| 2317 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2318 | case Primitive::kPrimByte: |
| 2319 | case Primitive::kPrimInt: |
| 2320 | case Primitive::kPrimChar: |
| 2321 | // Processing a Dex `int-to-short' instruction. |
| 2322 | locations->SetInAt(0, Location::Any()); |
| 2323 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2324 | break; |
| 2325 | |
| 2326 | default: |
| 2327 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2328 | << " to " << result_type; |
| 2329 | } |
| 2330 | break; |
| 2331 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2332 | case Primitive::kPrimInt: |
| 2333 | switch (input_type) { |
| 2334 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2335 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2336 | locations->SetInAt(0, Location::Any()); |
| 2337 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2338 | break; |
| 2339 | |
| 2340 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2341 | // Processing a Dex `float-to-int' instruction. |
| 2342 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2343 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2344 | break; |
| 2345 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2346 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2347 | // Processing a Dex `double-to-int' instruction. |
| 2348 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2349 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2350 | break; |
| 2351 | |
| 2352 | default: |
| 2353 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2354 | << " to " << result_type; |
| 2355 | } |
| 2356 | break; |
| 2357 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2358 | case Primitive::kPrimLong: |
| 2359 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2360 | case Primitive::kPrimBoolean: |
| 2361 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2362 | case Primitive::kPrimByte: |
| 2363 | case Primitive::kPrimShort: |
| 2364 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2366 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2367 | // TODO: We would benefit from a (to-be-implemented) |
| 2368 | // Location::RegisterOrStackSlot requirement for this input. |
| 2369 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2370 | locations->SetOut(Location::RequiresRegister()); |
| 2371 | break; |
| 2372 | |
| 2373 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2374 | // Processing a Dex `float-to-long' instruction. |
| 2375 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2376 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2377 | break; |
| 2378 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2379 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2380 | // Processing a Dex `double-to-long' instruction. |
| 2381 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2382 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2383 | break; |
| 2384 | |
| 2385 | default: |
| 2386 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2387 | << " to " << result_type; |
| 2388 | } |
| 2389 | break; |
| 2390 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2391 | case Primitive::kPrimChar: |
| 2392 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2393 | case Primitive::kPrimLong: |
| 2394 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2395 | case Primitive::kPrimBoolean: |
| 2396 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2397 | case Primitive::kPrimByte: |
| 2398 | case Primitive::kPrimShort: |
| 2399 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2400 | // Processing a Dex `int-to-char' instruction. |
| 2401 | locations->SetInAt(0, Location::Any()); |
| 2402 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2403 | break; |
| 2404 | |
| 2405 | default: |
| 2406 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2407 | << " to " << result_type; |
| 2408 | } |
| 2409 | break; |
| 2410 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2411 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2412 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2413 | case Primitive::kPrimBoolean: |
| 2414 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2415 | case Primitive::kPrimByte: |
| 2416 | case Primitive::kPrimShort: |
| 2417 | case Primitive::kPrimInt: |
| 2418 | case Primitive::kPrimChar: |
| 2419 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2420 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2421 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2422 | break; |
| 2423 | |
| 2424 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2425 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2426 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2427 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2428 | break; |
| 2429 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2430 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2431 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2432 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2433 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2434 | break; |
| 2435 | |
| 2436 | default: |
| 2437 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2438 | << " to " << result_type; |
| 2439 | }; |
| 2440 | break; |
| 2441 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2442 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2443 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2444 | case Primitive::kPrimBoolean: |
| 2445 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2446 | case Primitive::kPrimByte: |
| 2447 | case Primitive::kPrimShort: |
| 2448 | case Primitive::kPrimInt: |
| 2449 | case Primitive::kPrimChar: |
| 2450 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2451 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2452 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2453 | break; |
| 2454 | |
| 2455 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2456 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2457 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2458 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2459 | break; |
| 2460 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2461 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2462 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2463 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2464 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2465 | break; |
| 2466 | |
| 2467 | default: |
| 2468 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2469 | << " to " << result_type; |
| 2470 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2471 | break; |
| 2472 | |
| 2473 | default: |
| 2474 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2475 | << " to " << result_type; |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2480 | LocationSummary* locations = conversion->GetLocations(); |
| 2481 | Location out = locations->Out(); |
| 2482 | Location in = locations->InAt(0); |
| 2483 | Primitive::Type result_type = conversion->GetResultType(); |
| 2484 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2485 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2486 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2487 | case Primitive::kPrimByte: |
| 2488 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2489 | case Primitive::kPrimLong: |
| 2490 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2491 | case Primitive::kPrimBoolean: |
| 2492 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2493 | case Primitive::kPrimShort: |
| 2494 | case Primitive::kPrimInt: |
| 2495 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2496 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2497 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2498 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2499 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2500 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2501 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2502 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2503 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2504 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2505 | } |
| 2506 | break; |
| 2507 | |
| 2508 | default: |
| 2509 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2510 | << " to " << result_type; |
| 2511 | } |
| 2512 | break; |
| 2513 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2514 | case Primitive::kPrimShort: |
| 2515 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2516 | case Primitive::kPrimLong: |
| 2517 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2518 | case Primitive::kPrimBoolean: |
| 2519 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2520 | case Primitive::kPrimByte: |
| 2521 | case Primitive::kPrimInt: |
| 2522 | case Primitive::kPrimChar: |
| 2523 | // Processing a Dex `int-to-short' instruction. |
| 2524 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2525 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2526 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2527 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2528 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2529 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2530 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2531 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2532 | } |
| 2533 | break; |
| 2534 | |
| 2535 | default: |
| 2536 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2537 | << " to " << result_type; |
| 2538 | } |
| 2539 | break; |
| 2540 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2541 | case Primitive::kPrimInt: |
| 2542 | switch (input_type) { |
| 2543 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2544 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2545 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2546 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2547 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2548 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2549 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2550 | } else { |
| 2551 | DCHECK(in.IsConstant()); |
| 2552 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2553 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2554 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2555 | } |
| 2556 | break; |
| 2557 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2558 | case Primitive::kPrimFloat: { |
| 2559 | // Processing a Dex `float-to-int' instruction. |
| 2560 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2561 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2562 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2563 | |
| 2564 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2565 | // if input >= (float)INT_MAX goto done |
| 2566 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2567 | __ j(kAboveEqual, &done); |
| 2568 | // if input == NaN goto nan |
| 2569 | __ j(kUnordered, &nan); |
| 2570 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2571 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2572 | __ jmp(&done); |
| 2573 | __ Bind(&nan); |
| 2574 | // output = 0 |
| 2575 | __ xorl(output, output); |
| 2576 | __ Bind(&done); |
| 2577 | break; |
| 2578 | } |
| 2579 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2580 | case Primitive::kPrimDouble: { |
| 2581 | // Processing a Dex `double-to-int' instruction. |
| 2582 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2583 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2584 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2585 | |
| 2586 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2587 | // if input >= (double)INT_MAX goto done |
| 2588 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2589 | __ j(kAboveEqual, &done); |
| 2590 | // if input == NaN goto nan |
| 2591 | __ j(kUnordered, &nan); |
| 2592 | // output = double-to-int-truncate(input) |
| 2593 | __ cvttsd2si(output, input); |
| 2594 | __ jmp(&done); |
| 2595 | __ Bind(&nan); |
| 2596 | // output = 0 |
| 2597 | __ xorl(output, output); |
| 2598 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2599 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2600 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2601 | |
| 2602 | default: |
| 2603 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2604 | << " to " << result_type; |
| 2605 | } |
| 2606 | break; |
| 2607 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2608 | case Primitive::kPrimLong: |
| 2609 | switch (input_type) { |
| 2610 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2611 | case Primitive::kPrimBoolean: |
| 2612 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2613 | case Primitive::kPrimByte: |
| 2614 | case Primitive::kPrimShort: |
| 2615 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2616 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2617 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2618 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2619 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2620 | break; |
| 2621 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2622 | case Primitive::kPrimFloat: { |
| 2623 | // Processing a Dex `float-to-long' instruction. |
| 2624 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2625 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2626 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2627 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2628 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2629 | // if input >= (float)LONG_MAX goto done |
| 2630 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2631 | __ j(kAboveEqual, &done); |
| 2632 | // if input == NaN goto nan |
| 2633 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2634 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2635 | __ cvttss2si(output, input, true); |
| 2636 | __ jmp(&done); |
| 2637 | __ Bind(&nan); |
| 2638 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2639 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2640 | __ Bind(&done); |
| 2641 | break; |
| 2642 | } |
| 2643 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2644 | case Primitive::kPrimDouble: { |
| 2645 | // Processing a Dex `double-to-long' instruction. |
| 2646 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2647 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2648 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2649 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2650 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2651 | // if input >= (double)LONG_MAX goto done |
| 2652 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2653 | __ j(kAboveEqual, &done); |
| 2654 | // if input == NaN goto nan |
| 2655 | __ j(kUnordered, &nan); |
| 2656 | // output = double-to-long-truncate(input) |
| 2657 | __ cvttsd2si(output, input, true); |
| 2658 | __ jmp(&done); |
| 2659 | __ Bind(&nan); |
| 2660 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2661 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2662 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2663 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2664 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2665 | |
| 2666 | default: |
| 2667 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2668 | << " to " << result_type; |
| 2669 | } |
| 2670 | break; |
| 2671 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2672 | case Primitive::kPrimChar: |
| 2673 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2674 | case Primitive::kPrimLong: |
| 2675 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2676 | case Primitive::kPrimBoolean: |
| 2677 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2678 | case Primitive::kPrimByte: |
| 2679 | case Primitive::kPrimShort: |
| 2680 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2681 | // Processing a Dex `int-to-char' instruction. |
| 2682 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2683 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2684 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2685 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2686 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2687 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2688 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2689 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2690 | } |
| 2691 | break; |
| 2692 | |
| 2693 | default: |
| 2694 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2695 | << " to " << result_type; |
| 2696 | } |
| 2697 | break; |
| 2698 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2699 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2700 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2701 | case Primitive::kPrimBoolean: |
| 2702 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2703 | case Primitive::kPrimByte: |
| 2704 | case Primitive::kPrimShort: |
| 2705 | case Primitive::kPrimInt: |
| 2706 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2707 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2708 | if (in.IsRegister()) { |
| 2709 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2710 | } else if (in.IsConstant()) { |
| 2711 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2712 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2713 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2714 | } else { |
| 2715 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2716 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2717 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2718 | break; |
| 2719 | |
| 2720 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2721 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2722 | if (in.IsRegister()) { |
| 2723 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2724 | } else if (in.IsConstant()) { |
| 2725 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2726 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2727 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2728 | } else { |
| 2729 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2730 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2731 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2732 | break; |
| 2733 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2734 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2735 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2736 | if (in.IsFpuRegister()) { |
| 2737 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2738 | } else if (in.IsConstant()) { |
| 2739 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2740 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2741 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2742 | } else { |
| 2743 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2744 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2745 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2746 | break; |
| 2747 | |
| 2748 | default: |
| 2749 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2750 | << " to " << result_type; |
| 2751 | }; |
| 2752 | break; |
| 2753 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2754 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2755 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2756 | case Primitive::kPrimBoolean: |
| 2757 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2758 | case Primitive::kPrimByte: |
| 2759 | case Primitive::kPrimShort: |
| 2760 | case Primitive::kPrimInt: |
| 2761 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2762 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2763 | if (in.IsRegister()) { |
| 2764 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2765 | } else if (in.IsConstant()) { |
| 2766 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2767 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2768 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2769 | } else { |
| 2770 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2771 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2772 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2773 | break; |
| 2774 | |
| 2775 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2776 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2777 | if (in.IsRegister()) { |
| 2778 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2779 | } else if (in.IsConstant()) { |
| 2780 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2781 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2782 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2783 | } else { |
| 2784 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2785 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2786 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2787 | break; |
| 2788 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2789 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2790 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2791 | if (in.IsFpuRegister()) { |
| 2792 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2793 | } else if (in.IsConstant()) { |
| 2794 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2795 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2796 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2797 | } else { |
| 2798 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2799 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2800 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2801 | break; |
| 2802 | |
| 2803 | default: |
| 2804 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2805 | << " to " << result_type; |
| 2806 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2807 | break; |
| 2808 | |
| 2809 | default: |
| 2810 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2811 | << " to " << result_type; |
| 2812 | } |
| 2813 | } |
| 2814 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2815 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2816 | LocationSummary* locations = |
| 2817 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2818 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2819 | case Primitive::kPrimInt: { |
| 2820 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2821 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2822 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2823 | break; |
| 2824 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2825 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2826 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2827 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2828 | // 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] | 2829 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2830 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2831 | break; |
| 2832 | } |
| 2833 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2834 | case Primitive::kPrimDouble: |
| 2835 | case Primitive::kPrimFloat: { |
| 2836 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2837 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2838 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2839 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2840 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2841 | |
| 2842 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2843 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2844 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2848 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2849 | Location first = locations->InAt(0); |
| 2850 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2851 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2852 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2853 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2854 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2855 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2856 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2857 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2858 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2859 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2860 | } else { |
| 2861 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2862 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2863 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2864 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2865 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2866 | __ addl(out.AsRegister<CpuRegister>(), |
| 2867 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2868 | } else { |
| 2869 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2870 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2871 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2872 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2873 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2874 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2875 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2876 | break; |
| 2877 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2878 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2879 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2880 | if (second.IsRegister()) { |
| 2881 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2882 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2883 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2884 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2885 | } else { |
| 2886 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2887 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2888 | } |
| 2889 | } else { |
| 2890 | DCHECK(second.IsConstant()); |
| 2891 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2892 | int32_t int32_value = Low32Bits(value); |
| 2893 | DCHECK_EQ(int32_value, value); |
| 2894 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2895 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2896 | } else { |
| 2897 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2898 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2899 | } |
| 2900 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2901 | break; |
| 2902 | } |
| 2903 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2904 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2905 | if (second.IsFpuRegister()) { |
| 2906 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2907 | } else if (second.IsConstant()) { |
| 2908 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2909 | codegen_->LiteralFloatAddress( |
| 2910 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2911 | } else { |
| 2912 | DCHECK(second.IsStackSlot()); |
| 2913 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2914 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2915 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2916 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2920 | if (second.IsFpuRegister()) { |
| 2921 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2922 | } else if (second.IsConstant()) { |
| 2923 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2924 | codegen_->LiteralDoubleAddress( |
| 2925 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2926 | } else { |
| 2927 | DCHECK(second.IsDoubleStackSlot()); |
| 2928 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2929 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2930 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2931 | break; |
| 2932 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2933 | |
| 2934 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2935 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2940 | LocationSummary* locations = |
| 2941 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2942 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2943 | case Primitive::kPrimInt: { |
| 2944 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2945 | locations->SetInAt(1, Location::Any()); |
| 2946 | locations->SetOut(Location::SameAsFirstInput()); |
| 2947 | break; |
| 2948 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2949 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2950 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 2951 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2952 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2953 | break; |
| 2954 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2955 | case Primitive::kPrimFloat: |
| 2956 | case Primitive::kPrimDouble: { |
| 2957 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2958 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2959 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2960 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2961 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2962 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2963 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2964 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 2968 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2969 | Location first = locations->InAt(0); |
| 2970 | Location second = locations->InAt(1); |
| 2971 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2972 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2973 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2974 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2975 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2976 | } else if (second.IsConstant()) { |
| 2977 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2978 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2979 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2980 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2981 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2982 | break; |
| 2983 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2984 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2985 | if (second.IsConstant()) { |
| 2986 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2987 | DCHECK(IsInt<32>(value)); |
| 2988 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 2989 | } else { |
| 2990 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 2991 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2992 | break; |
| 2993 | } |
| 2994 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2995 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2996 | if (second.IsFpuRegister()) { |
| 2997 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2998 | } else if (second.IsConstant()) { |
| 2999 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3000 | codegen_->LiteralFloatAddress( |
| 3001 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3002 | } else { |
| 3003 | DCHECK(second.IsStackSlot()); |
| 3004 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3005 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3006 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3007 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3011 | if (second.IsFpuRegister()) { |
| 3012 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3013 | } else if (second.IsConstant()) { |
| 3014 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3015 | codegen_->LiteralDoubleAddress( |
| 3016 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3017 | } else { |
| 3018 | DCHECK(second.IsDoubleStackSlot()); |
| 3019 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3020 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3021 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3022 | break; |
| 3023 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3024 | |
| 3025 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3026 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3027 | } |
| 3028 | } |
| 3029 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3030 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3031 | LocationSummary* locations = |
| 3032 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3033 | switch (mul->GetResultType()) { |
| 3034 | case Primitive::kPrimInt: { |
| 3035 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3036 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3037 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3038 | // Can use 3 operand multiply. |
| 3039 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3040 | } else { |
| 3041 | locations->SetOut(Location::SameAsFirstInput()); |
| 3042 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3043 | break; |
| 3044 | } |
| 3045 | case Primitive::kPrimLong: { |
| 3046 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3047 | locations->SetInAt(1, Location::Any()); |
| 3048 | if (mul->InputAt(1)->IsLongConstant() && |
| 3049 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3050 | // Can use 3 operand multiply. |
| 3051 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3052 | } else { |
| 3053 | locations->SetOut(Location::SameAsFirstInput()); |
| 3054 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3055 | break; |
| 3056 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3057 | case Primitive::kPrimFloat: |
| 3058 | case Primitive::kPrimDouble: { |
| 3059 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3060 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3061 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3062 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3063 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3064 | |
| 3065 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3066 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3067 | } |
| 3068 | } |
| 3069 | |
| 3070 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3071 | LocationSummary* locations = mul->GetLocations(); |
| 3072 | Location first = locations->InAt(0); |
| 3073 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3074 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3075 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3076 | case Primitive::kPrimInt: |
| 3077 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3078 | // problems where the output may not be the same as the first operand. |
| 3079 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3080 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3081 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3082 | } else if (second.IsRegister()) { |
| 3083 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3084 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3085 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3086 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3087 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3088 | __ imull(first.AsRegister<CpuRegister>(), |
| 3089 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3090 | } |
| 3091 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3092 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3093 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3094 | // problems where the output may not be the same as the first operand. |
| 3095 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3096 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3097 | if (IsInt<32>(value)) { |
| 3098 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3099 | Immediate(static_cast<int32_t>(value))); |
| 3100 | } else { |
| 3101 | // Have to use the constant area. |
| 3102 | DCHECK(first.Equals(out)); |
| 3103 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3104 | } |
| 3105 | } else if (second.IsRegister()) { |
| 3106 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3107 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3108 | } else { |
| 3109 | DCHECK(second.IsDoubleStackSlot()); |
| 3110 | DCHECK(first.Equals(out)); |
| 3111 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3112 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3113 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3114 | break; |
| 3115 | } |
| 3116 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3117 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3118 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3119 | if (second.IsFpuRegister()) { |
| 3120 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3121 | } else if (second.IsConstant()) { |
| 3122 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3123 | codegen_->LiteralFloatAddress( |
| 3124 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3125 | } else { |
| 3126 | DCHECK(second.IsStackSlot()); |
| 3127 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3128 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3129 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3130 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3134 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3135 | if (second.IsFpuRegister()) { |
| 3136 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3137 | } else if (second.IsConstant()) { |
| 3138 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3139 | codegen_->LiteralDoubleAddress( |
| 3140 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3141 | } else { |
| 3142 | DCHECK(second.IsDoubleStackSlot()); |
| 3143 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3144 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3145 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3146 | break; |
| 3147 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3148 | |
| 3149 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3150 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3151 | } |
| 3152 | } |
| 3153 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3154 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3155 | uint32_t stack_adjustment, bool is_float) { |
| 3156 | if (source.IsStackSlot()) { |
| 3157 | DCHECK(is_float); |
| 3158 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3159 | } else if (source.IsDoubleStackSlot()) { |
| 3160 | DCHECK(!is_float); |
| 3161 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3162 | } else { |
| 3163 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3164 | if (is_float) { |
| 3165 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3166 | codegen_->Move(stack_temp, source); |
| 3167 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3168 | } else { |
| 3169 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3170 | codegen_->Move(stack_temp, source); |
| 3171 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3172 | } |
| 3173 | } |
| 3174 | } |
| 3175 | |
| 3176 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3177 | Primitive::Type type = rem->GetResultType(); |
| 3178 | bool is_float = type == Primitive::kPrimFloat; |
| 3179 | size_t elem_size = Primitive::ComponentSize(type); |
| 3180 | LocationSummary* locations = rem->GetLocations(); |
| 3181 | Location first = locations->InAt(0); |
| 3182 | Location second = locations->InAt(1); |
| 3183 | Location out = locations->Out(); |
| 3184 | |
| 3185 | // Create stack space for 2 elements. |
| 3186 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3187 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3188 | |
| 3189 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3190 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3191 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3192 | |
| 3193 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3194 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3195 | __ Bind(&retry); |
| 3196 | __ fprem(); |
| 3197 | |
| 3198 | // Move FP status to AX. |
| 3199 | __ fstsw(); |
| 3200 | |
| 3201 | // And see if the argument reduction is complete. This is signaled by the |
| 3202 | // C2 FPU flag bit set to 0. |
| 3203 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3204 | __ j(kNotEqual, &retry); |
| 3205 | |
| 3206 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3207 | // Store FP top of stack to real stack. |
| 3208 | if (is_float) { |
| 3209 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3210 | } else { |
| 3211 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3212 | } |
| 3213 | |
| 3214 | // Pop the 2 items from the FP stack. |
| 3215 | __ fucompp(); |
| 3216 | |
| 3217 | // Load the value from the stack into an XMM register. |
| 3218 | DCHECK(out.IsFpuRegister()) << out; |
| 3219 | if (is_float) { |
| 3220 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3221 | } else { |
| 3222 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3223 | } |
| 3224 | |
| 3225 | // And remove the temporary stack space we allocated. |
| 3226 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3227 | } |
| 3228 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3229 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3230 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3231 | |
| 3232 | LocationSummary* locations = instruction->GetLocations(); |
| 3233 | Location second = locations->InAt(1); |
| 3234 | DCHECK(second.IsConstant()); |
| 3235 | |
| 3236 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3237 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3238 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3239 | |
| 3240 | DCHECK(imm == 1 || imm == -1); |
| 3241 | |
| 3242 | switch (instruction->GetResultType()) { |
| 3243 | case Primitive::kPrimInt: { |
| 3244 | if (instruction->IsRem()) { |
| 3245 | __ xorl(output_register, output_register); |
| 3246 | } else { |
| 3247 | __ movl(output_register, input_register); |
| 3248 | if (imm == -1) { |
| 3249 | __ negl(output_register); |
| 3250 | } |
| 3251 | } |
| 3252 | break; |
| 3253 | } |
| 3254 | |
| 3255 | case Primitive::kPrimLong: { |
| 3256 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3257 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3258 | } else { |
| 3259 | __ movq(output_register, input_register); |
| 3260 | if (imm == -1) { |
| 3261 | __ negq(output_register); |
| 3262 | } |
| 3263 | } |
| 3264 | break; |
| 3265 | } |
| 3266 | |
| 3267 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3268 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3269 | } |
| 3270 | } |
| 3271 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3272 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3273 | LocationSummary* locations = instruction->GetLocations(); |
| 3274 | Location second = locations->InAt(1); |
| 3275 | |
| 3276 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3277 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3278 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3279 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3280 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3281 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3282 | |
| 3283 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3284 | |
| 3285 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3286 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3287 | __ testl(numerator, numerator); |
| 3288 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3289 | int shift = CTZ(imm); |
| 3290 | __ sarl(tmp, Immediate(shift)); |
| 3291 | |
| 3292 | if (imm < 0) { |
| 3293 | __ negl(tmp); |
| 3294 | } |
| 3295 | |
| 3296 | __ movl(output_register, tmp); |
| 3297 | } else { |
| 3298 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3299 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3300 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3301 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3302 | __ addq(rdx, numerator); |
| 3303 | __ testq(numerator, numerator); |
| 3304 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3305 | int shift = CTZ(imm); |
| 3306 | __ sarq(rdx, Immediate(shift)); |
| 3307 | |
| 3308 | if (imm < 0) { |
| 3309 | __ negq(rdx); |
| 3310 | } |
| 3311 | |
| 3312 | __ movq(output_register, rdx); |
| 3313 | } |
| 3314 | } |
| 3315 | |
| 3316 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3317 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3318 | |
| 3319 | LocationSummary* locations = instruction->GetLocations(); |
| 3320 | Location second = locations->InAt(1); |
| 3321 | |
| 3322 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3323 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3324 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3325 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3326 | : locations->Out().AsRegister<CpuRegister>(); |
| 3327 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3328 | |
| 3329 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3330 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3331 | if (instruction->IsDiv()) { |
| 3332 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3333 | } else { |
| 3334 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3335 | } |
| 3336 | |
| 3337 | int64_t magic; |
| 3338 | int shift; |
| 3339 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3340 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3341 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3342 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3343 | |
| 3344 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3345 | |
| 3346 | __ movl(numerator, eax); |
| 3347 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3348 | __ movl(eax, Immediate(magic)); |
| 3349 | __ imull(numerator); |
| 3350 | |
| 3351 | if (imm > 0 && magic < 0) { |
| 3352 | __ addl(edx, numerator); |
| 3353 | } else if (imm < 0 && magic > 0) { |
| 3354 | __ subl(edx, numerator); |
| 3355 | } |
| 3356 | |
| 3357 | if (shift != 0) { |
| 3358 | __ sarl(edx, Immediate(shift)); |
| 3359 | } |
| 3360 | |
| 3361 | __ movl(eax, edx); |
| 3362 | __ shrl(edx, Immediate(31)); |
| 3363 | __ addl(edx, eax); |
| 3364 | |
| 3365 | if (instruction->IsRem()) { |
| 3366 | __ movl(eax, numerator); |
| 3367 | __ imull(edx, Immediate(imm)); |
| 3368 | __ subl(eax, edx); |
| 3369 | __ movl(edx, eax); |
| 3370 | } else { |
| 3371 | __ movl(eax, edx); |
| 3372 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3373 | } else { |
| 3374 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3375 | |
| 3376 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3377 | |
| 3378 | CpuRegister rax = eax; |
| 3379 | CpuRegister rdx = edx; |
| 3380 | |
| 3381 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3382 | |
| 3383 | // Save the numerator. |
| 3384 | __ movq(numerator, rax); |
| 3385 | |
| 3386 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3387 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3388 | |
| 3389 | // RDX:RAX = magic * numerator |
| 3390 | __ imulq(numerator); |
| 3391 | |
| 3392 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3393 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3394 | __ addq(rdx, numerator); |
| 3395 | } else if (imm < 0 && magic > 0) { |
| 3396 | // RDX -= numerator |
| 3397 | __ subq(rdx, numerator); |
| 3398 | } |
| 3399 | |
| 3400 | // Shift if needed. |
| 3401 | if (shift != 0) { |
| 3402 | __ sarq(rdx, Immediate(shift)); |
| 3403 | } |
| 3404 | |
| 3405 | // RDX += 1 if RDX < 0 |
| 3406 | __ movq(rax, rdx); |
| 3407 | __ shrq(rdx, Immediate(63)); |
| 3408 | __ addq(rdx, rax); |
| 3409 | |
| 3410 | if (instruction->IsRem()) { |
| 3411 | __ movq(rax, numerator); |
| 3412 | |
| 3413 | if (IsInt<32>(imm)) { |
| 3414 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3415 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3416 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3417 | } |
| 3418 | |
| 3419 | __ subq(rax, rdx); |
| 3420 | __ movq(rdx, rax); |
| 3421 | } else { |
| 3422 | __ movq(rax, rdx); |
| 3423 | } |
| 3424 | } |
| 3425 | } |
| 3426 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3427 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3428 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3429 | Primitive::Type type = instruction->GetResultType(); |
| 3430 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3431 | |
| 3432 | bool is_div = instruction->IsDiv(); |
| 3433 | LocationSummary* locations = instruction->GetLocations(); |
| 3434 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3435 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3436 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3437 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3438 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3439 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3440 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3441 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3442 | int64_t imm = Int64FromConstant(second.GetConstant()); |
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 (imm == 0) { |
| 3445 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3446 | } else if (imm == 1 || imm == -1) { |
| 3447 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3448 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3449 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3450 | } else { |
| 3451 | DCHECK(imm <= -2 || imm >= 2); |
| 3452 | GenerateDivRemWithAnyConstant(instruction); |
| 3453 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3454 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3455 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3456 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3457 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3458 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3459 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3460 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3461 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3462 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3463 | // so it's safe to just use negl instead of more complex comparisons. |
| 3464 | if (type == Primitive::kPrimInt) { |
| 3465 | __ cmpl(second_reg, Immediate(-1)); |
| 3466 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3467 | // edx:eax <- sign-extended of eax |
| 3468 | __ cdq(); |
| 3469 | // eax = quotient, edx = remainder |
| 3470 | __ idivl(second_reg); |
| 3471 | } else { |
| 3472 | __ cmpq(second_reg, Immediate(-1)); |
| 3473 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3474 | // rdx:rax <- sign-extended of rax |
| 3475 | __ cqo(); |
| 3476 | // rax = quotient, rdx = remainder |
| 3477 | __ idivq(second_reg); |
| 3478 | } |
| 3479 | __ Bind(slow_path->GetExitLabel()); |
| 3480 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3481 | } |
| 3482 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3483 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3484 | LocationSummary* locations = |
| 3485 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3486 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3487 | case Primitive::kPrimInt: |
| 3488 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3489 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3490 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3491 | locations->SetOut(Location::SameAsFirstInput()); |
| 3492 | // Intel uses edx:eax as the dividend. |
| 3493 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3494 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3495 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3496 | // output and request another temp. |
| 3497 | if (div->InputAt(1)->IsConstant()) { |
| 3498 | locations->AddTemp(Location::RequiresRegister()); |
| 3499 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3500 | break; |
| 3501 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3502 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3503 | case Primitive::kPrimFloat: |
| 3504 | case Primitive::kPrimDouble: { |
| 3505 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3506 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3507 | locations->SetOut(Location::SameAsFirstInput()); |
| 3508 | break; |
| 3509 | } |
| 3510 | |
| 3511 | default: |
| 3512 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3513 | } |
| 3514 | } |
| 3515 | |
| 3516 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3517 | LocationSummary* locations = div->GetLocations(); |
| 3518 | Location first = locations->InAt(0); |
| 3519 | Location second = locations->InAt(1); |
| 3520 | DCHECK(first.Equals(locations->Out())); |
| 3521 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3522 | Primitive::Type type = div->GetResultType(); |
| 3523 | switch (type) { |
| 3524 | case Primitive::kPrimInt: |
| 3525 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3526 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3527 | break; |
| 3528 | } |
| 3529 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3530 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3531 | if (second.IsFpuRegister()) { |
| 3532 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3533 | } else if (second.IsConstant()) { |
| 3534 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3535 | codegen_->LiteralFloatAddress( |
| 3536 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3537 | } else { |
| 3538 | DCHECK(second.IsStackSlot()); |
| 3539 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3540 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3541 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3542 | break; |
| 3543 | } |
| 3544 | |
| 3545 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3546 | if (second.IsFpuRegister()) { |
| 3547 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3548 | } else if (second.IsConstant()) { |
| 3549 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3550 | codegen_->LiteralDoubleAddress( |
| 3551 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3552 | } else { |
| 3553 | DCHECK(second.IsDoubleStackSlot()); |
| 3554 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3555 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3556 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3557 | break; |
| 3558 | } |
| 3559 | |
| 3560 | default: |
| 3561 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3562 | } |
| 3563 | } |
| 3564 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3565 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3566 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3567 | LocationSummary* locations = |
| 3568 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3569 | |
| 3570 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3571 | case Primitive::kPrimInt: |
| 3572 | case Primitive::kPrimLong: { |
| 3573 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3574 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3575 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3576 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3577 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3578 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3579 | // output and request another temp. |
| 3580 | if (rem->InputAt(1)->IsConstant()) { |
| 3581 | locations->AddTemp(Location::RequiresRegister()); |
| 3582 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3583 | break; |
| 3584 | } |
| 3585 | |
| 3586 | case Primitive::kPrimFloat: |
| 3587 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3588 | locations->SetInAt(0, Location::Any()); |
| 3589 | locations->SetInAt(1, Location::Any()); |
| 3590 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3591 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3592 | break; |
| 3593 | } |
| 3594 | |
| 3595 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3596 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3597 | } |
| 3598 | } |
| 3599 | |
| 3600 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3601 | Primitive::Type type = rem->GetResultType(); |
| 3602 | switch (type) { |
| 3603 | case Primitive::kPrimInt: |
| 3604 | case Primitive::kPrimLong: { |
| 3605 | GenerateDivRemIntegral(rem); |
| 3606 | break; |
| 3607 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3608 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3609 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3610 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3611 | break; |
| 3612 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3613 | default: |
| 3614 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3615 | } |
| 3616 | } |
| 3617 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3618 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3619 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3620 | locations->SetInAt(0, Location::Any()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3624 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3625 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3626 | codegen_->AddSlowPath(slow_path); |
| 3627 | |
| 3628 | LocationSummary* locations = instruction->GetLocations(); |
| 3629 | Location value = locations->InAt(0); |
| 3630 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3631 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3632 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3633 | case Primitive::kPrimByte: |
| 3634 | case Primitive::kPrimChar: |
| 3635 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3636 | case Primitive::kPrimInt: { |
| 3637 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3638 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3639 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3640 | } else if (value.IsStackSlot()) { |
| 3641 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3642 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3643 | } else { |
| 3644 | DCHECK(value.IsConstant()) << value; |
| 3645 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3646 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3647 | } |
| 3648 | } |
| 3649 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3650 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3651 | case Primitive::kPrimLong: { |
| 3652 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3653 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3654 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3655 | } else if (value.IsDoubleStackSlot()) { |
| 3656 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3657 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3658 | } else { |
| 3659 | DCHECK(value.IsConstant()) << value; |
| 3660 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3661 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3662 | } |
| 3663 | } |
| 3664 | break; |
| 3665 | } |
| 3666 | default: |
| 3667 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3668 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3669 | } |
| 3670 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3671 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3672 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3673 | |
| 3674 | LocationSummary* locations = |
| 3675 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3676 | |
| 3677 | switch (op->GetResultType()) { |
| 3678 | case Primitive::kPrimInt: |
| 3679 | case Primitive::kPrimLong: { |
| 3680 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3681 | // The shift count needs to be in CL. |
| 3682 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3683 | locations->SetOut(Location::SameAsFirstInput()); |
| 3684 | break; |
| 3685 | } |
| 3686 | default: |
| 3687 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3688 | } |
| 3689 | } |
| 3690 | |
| 3691 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3692 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3693 | |
| 3694 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3695 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3696 | Location second = locations->InAt(1); |
| 3697 | |
| 3698 | switch (op->GetResultType()) { |
| 3699 | case Primitive::kPrimInt: { |
| 3700 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3701 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3702 | if (op->IsShl()) { |
| 3703 | __ shll(first_reg, second_reg); |
| 3704 | } else if (op->IsShr()) { |
| 3705 | __ sarl(first_reg, second_reg); |
| 3706 | } else { |
| 3707 | __ shrl(first_reg, second_reg); |
| 3708 | } |
| 3709 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3710 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3711 | if (op->IsShl()) { |
| 3712 | __ shll(first_reg, imm); |
| 3713 | } else if (op->IsShr()) { |
| 3714 | __ sarl(first_reg, imm); |
| 3715 | } else { |
| 3716 | __ shrl(first_reg, imm); |
| 3717 | } |
| 3718 | } |
| 3719 | break; |
| 3720 | } |
| 3721 | case Primitive::kPrimLong: { |
| 3722 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3723 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3724 | if (op->IsShl()) { |
| 3725 | __ shlq(first_reg, second_reg); |
| 3726 | } else if (op->IsShr()) { |
| 3727 | __ sarq(first_reg, second_reg); |
| 3728 | } else { |
| 3729 | __ shrq(first_reg, second_reg); |
| 3730 | } |
| 3731 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3732 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3733 | if (op->IsShl()) { |
| 3734 | __ shlq(first_reg, imm); |
| 3735 | } else if (op->IsShr()) { |
| 3736 | __ sarq(first_reg, imm); |
| 3737 | } else { |
| 3738 | __ shrq(first_reg, imm); |
| 3739 | } |
| 3740 | } |
| 3741 | break; |
| 3742 | } |
| 3743 | default: |
| 3744 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3745 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3746 | } |
| 3747 | } |
| 3748 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3749 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3750 | LocationSummary* locations = |
| 3751 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3752 | |
| 3753 | switch (ror->GetResultType()) { |
| 3754 | case Primitive::kPrimInt: |
| 3755 | case Primitive::kPrimLong: { |
| 3756 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3757 | // The shift count needs to be in CL (unless it is a constant). |
| 3758 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3759 | locations->SetOut(Location::SameAsFirstInput()); |
| 3760 | break; |
| 3761 | } |
| 3762 | default: |
| 3763 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3764 | UNREACHABLE(); |
| 3765 | } |
| 3766 | } |
| 3767 | |
| 3768 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 3769 | LocationSummary* locations = ror->GetLocations(); |
| 3770 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3771 | Location second = locations->InAt(1); |
| 3772 | |
| 3773 | switch (ror->GetResultType()) { |
| 3774 | case Primitive::kPrimInt: |
| 3775 | if (second.IsRegister()) { |
| 3776 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3777 | __ rorl(first_reg, second_reg); |
| 3778 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3779 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3780 | __ rorl(first_reg, imm); |
| 3781 | } |
| 3782 | break; |
| 3783 | case Primitive::kPrimLong: |
| 3784 | if (second.IsRegister()) { |
| 3785 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3786 | __ rorq(first_reg, second_reg); |
| 3787 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3788 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3789 | __ rorq(first_reg, imm); |
| 3790 | } |
| 3791 | break; |
| 3792 | default: |
| 3793 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3794 | UNREACHABLE(); |
| 3795 | } |
| 3796 | } |
| 3797 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3798 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3799 | HandleShift(shl); |
| 3800 | } |
| 3801 | |
| 3802 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3803 | HandleShift(shl); |
| 3804 | } |
| 3805 | |
| 3806 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3807 | HandleShift(shr); |
| 3808 | } |
| 3809 | |
| 3810 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3811 | HandleShift(shr); |
| 3812 | } |
| 3813 | |
| 3814 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3815 | HandleShift(ushr); |
| 3816 | } |
| 3817 | |
| 3818 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3819 | HandleShift(ushr); |
| 3820 | } |
| 3821 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3822 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3823 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3824 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3825 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3826 | if (instruction->IsStringAlloc()) { |
| 3827 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3828 | } else { |
| 3829 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3830 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3831 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3832 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3836 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3837 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3838 | if (instruction->IsStringAlloc()) { |
| 3839 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3840 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3841 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3842 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 3843 | __ call(Address(temp, code_offset.SizeValue())); |
| 3844 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3845 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3846 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3847 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3848 | DCHECK(!codegen_->IsLeafMethod()); |
| 3849 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3850 | } |
| 3851 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3852 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3853 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3854 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3855 | InvokeRuntimeCallingConvention calling_convention; |
| 3856 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3857 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3858 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3859 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3863 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3864 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3865 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3866 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3867 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3868 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3869 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3870 | |
| 3871 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3872 | } |
| 3873 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3874 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3875 | LocationSummary* locations = |
| 3876 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3877 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3878 | if (location.IsStackSlot()) { |
| 3879 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3880 | } else if (location.IsDoubleStackSlot()) { |
| 3881 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3882 | } |
| 3883 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3884 | } |
| 3885 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3886 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3887 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3888 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3892 | LocationSummary* locations = |
| 3893 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3894 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3895 | } |
| 3896 | |
| 3897 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3898 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3899 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3900 | } |
| 3901 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3902 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3903 | LocationSummary* locations = |
| 3904 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3905 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3906 | locations->SetOut(Location::RequiresRegister()); |
| 3907 | } |
| 3908 | |
| 3909 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3910 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3911 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 3912 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3913 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 3914 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 3915 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3916 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 3917 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 3918 | instruction->GetIndex(), kX86_64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 3919 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 3920 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 3921 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 3922 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 3923 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3924 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3925 | } |
| 3926 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3927 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3928 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3929 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3930 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3931 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3932 | } |
| 3933 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3934 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3935 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3936 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3937 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3938 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3939 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3940 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3941 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3942 | break; |
| 3943 | |
| 3944 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3945 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3946 | break; |
| 3947 | |
| 3948 | default: |
| 3949 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3950 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3951 | } |
| 3952 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3953 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3954 | LocationSummary* locations = |
| 3955 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3956 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3957 | locations->SetOut(Location::SameAsFirstInput()); |
| 3958 | } |
| 3959 | |
| 3960 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3961 | LocationSummary* locations = bool_not->GetLocations(); |
| 3962 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3963 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3964 | Location out = locations->Out(); |
| 3965 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 3966 | } |
| 3967 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3968 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3969 | LocationSummary* locations = |
| 3970 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3971 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3972 | locations->SetInAt(i, Location::Any()); |
| 3973 | } |
| 3974 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3975 | } |
| 3976 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3977 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3978 | LOG(FATAL) << "Unimplemented"; |
| 3979 | } |
| 3980 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3981 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3982 | /* |
| 3983 | * 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] | 3984 | * 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] | 3985 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3986 | */ |
| 3987 | switch (kind) { |
| 3988 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 3989 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3990 | break; |
| 3991 | } |
| 3992 | case MemBarrierKind::kAnyStore: |
| 3993 | case MemBarrierKind::kLoadAny: |
| 3994 | case MemBarrierKind::kStoreStore: { |
| 3995 | // nop |
| 3996 | break; |
| 3997 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 3998 | case MemBarrierKind::kNTStoreStore: |
| 3999 | // Non-Temporal Store/Store needs an explicit fence. |
| 4000 | MemoryFence(/* non-temporal */ true); |
| 4001 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4002 | } |
| 4003 | } |
| 4004 | |
| 4005 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4006 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4007 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4008 | bool object_field_get_with_read_barrier = |
| 4009 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4010 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4011 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4012 | object_field_get_with_read_barrier ? |
| 4013 | LocationSummary::kCallOnSlowPath : |
| 4014 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4015 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4016 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4017 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4018 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4019 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4020 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4021 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4022 | // The output overlaps for an object field get when read barriers |
| 4023 | // are enabled: we do not want the move to overwrite the object's |
| 4024 | // location, as we need it to emit the read barrier. |
| 4025 | locations->SetOut( |
| 4026 | Location::RequiresRegister(), |
| 4027 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4028 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4029 | } |
| 4030 | |
| 4031 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4032 | const FieldInfo& field_info) { |
| 4033 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4034 | |
| 4035 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4036 | Location base_loc = locations->InAt(0); |
| 4037 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4038 | Location out = locations->Out(); |
| 4039 | bool is_volatile = field_info.IsVolatile(); |
| 4040 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4041 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4042 | |
| 4043 | switch (field_type) { |
| 4044 | case Primitive::kPrimBoolean: { |
| 4045 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4046 | break; |
| 4047 | } |
| 4048 | |
| 4049 | case Primitive::kPrimByte: { |
| 4050 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4051 | break; |
| 4052 | } |
| 4053 | |
| 4054 | case Primitive::kPrimShort: { |
| 4055 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4056 | break; |
| 4057 | } |
| 4058 | |
| 4059 | case Primitive::kPrimChar: { |
| 4060 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4061 | break; |
| 4062 | } |
| 4063 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4064 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4065 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4066 | break; |
| 4067 | } |
| 4068 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4069 | case Primitive::kPrimNot: { |
| 4070 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4071 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4072 | // Note that a potential implicit null check is handled in this |
| 4073 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4074 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4075 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4076 | if (is_volatile) { |
| 4077 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4078 | } |
| 4079 | } else { |
| 4080 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4081 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4082 | if (is_volatile) { |
| 4083 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4084 | } |
| 4085 | // If read barriers are enabled, emit read barriers other than |
| 4086 | // Baker's using a slow path (and also unpoison the loaded |
| 4087 | // reference, if heap poisoning is enabled). |
| 4088 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4089 | } |
| 4090 | break; |
| 4091 | } |
| 4092 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4093 | case Primitive::kPrimLong: { |
| 4094 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4095 | break; |
| 4096 | } |
| 4097 | |
| 4098 | case Primitive::kPrimFloat: { |
| 4099 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4100 | break; |
| 4101 | } |
| 4102 | |
| 4103 | case Primitive::kPrimDouble: { |
| 4104 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4105 | break; |
| 4106 | } |
| 4107 | |
| 4108 | case Primitive::kPrimVoid: |
| 4109 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4110 | UNREACHABLE(); |
| 4111 | } |
| 4112 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4113 | if (field_type == Primitive::kPrimNot) { |
| 4114 | // Potential implicit null checks, in the case of reference |
| 4115 | // fields, are handled in the previous switch statement. |
| 4116 | } else { |
| 4117 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4118 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4119 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4120 | if (is_volatile) { |
| 4121 | if (field_type == Primitive::kPrimNot) { |
| 4122 | // Memory barriers, in the case of references, are also handled |
| 4123 | // in the previous switch statement. |
| 4124 | } else { |
| 4125 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4126 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4127 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4128 | } |
| 4129 | |
| 4130 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4131 | const FieldInfo& field_info) { |
| 4132 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4133 | |
| 4134 | LocationSummary* locations = |
| 4135 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4136 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4137 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4138 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4139 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4140 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4141 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4142 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4143 | if (is_volatile) { |
| 4144 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4145 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4146 | } else { |
| 4147 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4148 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4149 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4150 | if (is_volatile) { |
| 4151 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4152 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4153 | } else { |
| 4154 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4155 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4156 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4157 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4158 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4159 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4160 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4161 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4162 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4163 | locations->AddTemp(Location::RequiresRegister()); |
| 4164 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4165 | } |
| 4166 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4167 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4168 | const FieldInfo& field_info, |
| 4169 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4170 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4171 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4172 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4173 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4174 | Location value = locations->InAt(1); |
| 4175 | bool is_volatile = field_info.IsVolatile(); |
| 4176 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4177 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4178 | |
| 4179 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4180 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4181 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4182 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4183 | bool maybe_record_implicit_null_check_done = false; |
| 4184 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4185 | switch (field_type) { |
| 4186 | case Primitive::kPrimBoolean: |
| 4187 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4188 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4189 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4190 | __ movb(Address(base, offset), Immediate(v)); |
| 4191 | } else { |
| 4192 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4193 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4194 | break; |
| 4195 | } |
| 4196 | |
| 4197 | case Primitive::kPrimShort: |
| 4198 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4199 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4200 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4201 | __ movw(Address(base, offset), Immediate(v)); |
| 4202 | } else { |
| 4203 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4204 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4205 | break; |
| 4206 | } |
| 4207 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4208 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4209 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4210 | if (value.IsConstant()) { |
| 4211 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4212 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4213 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4214 | // Note: if heap poisoning is enabled, no need to poison |
| 4215 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4216 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4217 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4218 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4219 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4220 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4221 | __ PoisonHeapReference(temp); |
| 4222 | __ movl(Address(base, offset), temp); |
| 4223 | } else { |
| 4224 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4225 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4226 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4227 | break; |
| 4228 | } |
| 4229 | |
| 4230 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4231 | if (value.IsConstant()) { |
| 4232 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4233 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4234 | Address(base, offset + sizeof(int32_t)), |
| 4235 | v, |
| 4236 | instruction); |
| 4237 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4238 | } else { |
| 4239 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4240 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4241 | break; |
| 4242 | } |
| 4243 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4244 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4245 | if (value.IsConstant()) { |
| 4246 | int32_t v = |
| 4247 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4248 | __ movl(Address(base, offset), Immediate(v)); |
| 4249 | } else { |
| 4250 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4251 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4252 | break; |
| 4253 | } |
| 4254 | |
| 4255 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4256 | if (value.IsConstant()) { |
| 4257 | int64_t v = |
| 4258 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4259 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4260 | Address(base, offset + sizeof(int32_t)), |
| 4261 | v, |
| 4262 | instruction); |
| 4263 | maybe_record_implicit_null_check_done = true; |
| 4264 | } else { |
| 4265 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4266 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4267 | break; |
| 4268 | } |
| 4269 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4270 | case Primitive::kPrimVoid: |
| 4271 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4272 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4273 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4274 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4275 | if (!maybe_record_implicit_null_check_done) { |
| 4276 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4277 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4278 | |
| 4279 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4280 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4281 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4282 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4283 | } |
| 4284 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4285 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4286 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4287 | } |
| 4288 | } |
| 4289 | |
| 4290 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4291 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4292 | } |
| 4293 | |
| 4294 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4295 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4296 | } |
| 4297 | |
| 4298 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4299 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4303 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4304 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4305 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4306 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4307 | HandleFieldGet(instruction); |
| 4308 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4309 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4310 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4311 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4312 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4313 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4314 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4315 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4316 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4317 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4318 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4319 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4320 | } |
| 4321 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4322 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4323 | HUnresolvedInstanceFieldGet* instruction) { |
| 4324 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4325 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4326 | instruction, instruction->GetFieldType(), calling_convention); |
| 4327 | } |
| 4328 | |
| 4329 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4330 | HUnresolvedInstanceFieldGet* instruction) { |
| 4331 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4332 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4333 | instruction->GetFieldType(), |
| 4334 | instruction->GetFieldIndex(), |
| 4335 | instruction->GetDexPc(), |
| 4336 | calling_convention); |
| 4337 | } |
| 4338 | |
| 4339 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4340 | HUnresolvedInstanceFieldSet* instruction) { |
| 4341 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4342 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4343 | instruction, instruction->GetFieldType(), calling_convention); |
| 4344 | } |
| 4345 | |
| 4346 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4347 | HUnresolvedInstanceFieldSet* instruction) { |
| 4348 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4349 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4350 | instruction->GetFieldType(), |
| 4351 | instruction->GetFieldIndex(), |
| 4352 | instruction->GetDexPc(), |
| 4353 | calling_convention); |
| 4354 | } |
| 4355 | |
| 4356 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4357 | HUnresolvedStaticFieldGet* instruction) { |
| 4358 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4359 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4360 | instruction, instruction->GetFieldType(), calling_convention); |
| 4361 | } |
| 4362 | |
| 4363 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4364 | HUnresolvedStaticFieldGet* instruction) { |
| 4365 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4366 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4367 | instruction->GetFieldType(), |
| 4368 | instruction->GetFieldIndex(), |
| 4369 | instruction->GetDexPc(), |
| 4370 | calling_convention); |
| 4371 | } |
| 4372 | |
| 4373 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4374 | HUnresolvedStaticFieldSet* instruction) { |
| 4375 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4376 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4377 | instruction, instruction->GetFieldType(), calling_convention); |
| 4378 | } |
| 4379 | |
| 4380 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4381 | HUnresolvedStaticFieldSet* instruction) { |
| 4382 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4383 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4384 | instruction->GetFieldType(), |
| 4385 | instruction->GetFieldIndex(), |
| 4386 | instruction->GetDexPc(), |
| 4387 | calling_convention); |
| 4388 | } |
| 4389 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4390 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4391 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4392 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4393 | ? Location::RequiresRegister() |
| 4394 | : Location::Any(); |
| 4395 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4396 | } |
| 4397 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4398 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4399 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4400 | return; |
| 4401 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4402 | LocationSummary* locations = instruction->GetLocations(); |
| 4403 | Location obj = locations->InAt(0); |
| 4404 | |
| 4405 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4406 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4407 | } |
| 4408 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4409 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4410 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4411 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4412 | |
| 4413 | LocationSummary* locations = instruction->GetLocations(); |
| 4414 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4415 | |
| 4416 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4417 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4418 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4419 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4420 | } else { |
| 4421 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4422 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4423 | __ jmp(slow_path->GetEntryLabel()); |
| 4424 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4425 | } |
| 4426 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4427 | } |
| 4428 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4429 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4430 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4431 | } |
| 4432 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4433 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4434 | bool object_array_get_with_read_barrier = |
| 4435 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4436 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4437 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4438 | object_array_get_with_read_barrier ? |
| 4439 | LocationSummary::kCallOnSlowPath : |
| 4440 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4441 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4442 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4443 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4444 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4445 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4446 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4447 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4448 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4449 | // The output overlaps for an object array get when read barriers |
| 4450 | // are enabled: we do not want the move to overwrite the array's |
| 4451 | // location, as we need it to emit the read barrier. |
| 4452 | locations->SetOut( |
| 4453 | Location::RequiresRegister(), |
| 4454 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4455 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4456 | } |
| 4457 | |
| 4458 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4459 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4460 | Location obj_loc = locations->InAt(0); |
| 4461 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4462 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4463 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4464 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4465 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4466 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4467 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4468 | case Primitive::kPrimBoolean: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4469 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4470 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4471 | break; |
| 4472 | } |
| 4473 | |
| 4474 | case Primitive::kPrimByte: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4475 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4476 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4477 | break; |
| 4478 | } |
| 4479 | |
| 4480 | case Primitive::kPrimShort: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4481 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4482 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4483 | break; |
| 4484 | } |
| 4485 | |
| 4486 | case Primitive::kPrimChar: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4487 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4488 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4489 | break; |
| 4490 | } |
| 4491 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4492 | case Primitive::kPrimInt: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4493 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4494 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4495 | break; |
| 4496 | } |
| 4497 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4498 | case Primitive::kPrimNot: { |
| 4499 | static_assert( |
| 4500 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4501 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4502 | // /* HeapReference<Object> */ out = |
| 4503 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4504 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4505 | // Note that a potential implicit null check is handled in this |
| 4506 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4507 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4508 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4509 | } else { |
| 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)); |
| 4512 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4513 | // If read barriers are enabled, emit read barriers other than |
| 4514 | // Baker's using a slow path (and also unpoison the loaded |
| 4515 | // reference, if heap poisoning is enabled). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4516 | if (index.IsConstant()) { |
| 4517 | uint32_t offset = |
| 4518 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4519 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4520 | } else { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4521 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4522 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4523 | } |
| 4524 | } |
| 4525 | break; |
| 4526 | } |
| 4527 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4528 | case Primitive::kPrimLong: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4529 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4530 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4531 | break; |
| 4532 | } |
| 4533 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4534 | case Primitive::kPrimFloat: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4535 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4536 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4537 | break; |
| 4538 | } |
| 4539 | |
| 4540 | case Primitive::kPrimDouble: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4541 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4542 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4543 | break; |
| 4544 | } |
| 4545 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4546 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4547 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4548 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4549 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4550 | |
| 4551 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4552 | // Potential implicit null checks, in the case of reference |
| 4553 | // arrays, are handled in the previous switch statement. |
| 4554 | } else { |
| 4555 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4556 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4557 | } |
| 4558 | |
| 4559 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4560 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4561 | |
| 4562 | bool needs_write_barrier = |
| 4563 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4564 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4565 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4566 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4567 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4568 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4569 | LocationSummary::kCallOnSlowPath : |
| 4570 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4571 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4572 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4573 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4574 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4575 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4576 | } else { |
| 4577 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4578 | } |
| 4579 | |
| 4580 | if (needs_write_barrier) { |
| 4581 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4582 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4583 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4584 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4588 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4589 | Location array_loc = locations->InAt(0); |
| 4590 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4591 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4592 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4593 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4594 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4595 | bool needs_write_barrier = |
| 4596 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4597 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4598 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4599 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4600 | |
| 4601 | switch (value_type) { |
| 4602 | case Primitive::kPrimBoolean: |
| 4603 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4604 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4605 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4606 | if (value.IsRegister()) { |
| 4607 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4608 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4609 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4610 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4611 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4612 | break; |
| 4613 | } |
| 4614 | |
| 4615 | case Primitive::kPrimShort: |
| 4616 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4617 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4618 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4619 | if (value.IsRegister()) { |
| 4620 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4621 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4622 | DCHECK(value.IsConstant()) << value; |
| 4623 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4624 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4625 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4626 | break; |
| 4627 | } |
| 4628 | |
| 4629 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4630 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4631 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4632 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4633 | if (!value.IsRegister()) { |
| 4634 | // Just setting null. |
| 4635 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4636 | DCHECK(value.IsConstant()) << value; |
| 4637 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4638 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4639 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4640 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4641 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4642 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4643 | |
| 4644 | DCHECK(needs_write_barrier); |
| 4645 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4646 | // We cannot use a NearLabel for `done`, as its range may be too |
| 4647 | // short when Baker read barriers are enabled. |
| 4648 | Label done; |
| 4649 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4650 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4651 | Location temp_loc = locations->GetTemp(0); |
| 4652 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4653 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4654 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4655 | codegen_->AddSlowPath(slow_path); |
| 4656 | if (instruction->GetValueCanBeNull()) { |
| 4657 | __ testl(register_value, register_value); |
| 4658 | __ j(kNotEqual, ¬_null); |
| 4659 | __ movl(address, Immediate(0)); |
| 4660 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4661 | __ jmp(&done); |
| 4662 | __ Bind(¬_null); |
| 4663 | } |
| 4664 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4665 | // Note that when Baker read barriers are enabled, the type |
| 4666 | // checks are performed without read barriers. This is fine, |
| 4667 | // even in the case where a class object is in the from-space |
| 4668 | // after the flip, as a comparison involving such a type would |
| 4669 | // not produce a false positive; it may of course produce a |
| 4670 | // false negative, in which case we would take the ArraySet |
| 4671 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4672 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4673 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4674 | __ movl(temp, Address(array, class_offset)); |
| 4675 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4676 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4677 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4678 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4679 | __ movl(temp, Address(temp, component_offset)); |
| 4680 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4681 | // nor the object reference in `register_value->klass`, as |
| 4682 | // we are comparing two poisoned references. |
| 4683 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4684 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4685 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4686 | __ j(kEqual, &do_put); |
| 4687 | // If heap poisoning is enabled, the `temp` reference has |
| 4688 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4689 | __ MaybeUnpoisonHeapReference(temp); |
| 4690 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 4691 | // If heap poisoning is enabled, no need to unpoison the |
| 4692 | // heap reference loaded below, as it is only used for a |
| 4693 | // comparison with null. |
| 4694 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 4695 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4696 | __ Bind(&do_put); |
| 4697 | } else { |
| 4698 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4699 | } |
| 4700 | } |
| 4701 | |
| 4702 | if (kPoisonHeapReferences) { |
| 4703 | __ movl(temp, register_value); |
| 4704 | __ PoisonHeapReference(temp); |
| 4705 | __ movl(address, temp); |
| 4706 | } else { |
| 4707 | __ movl(address, register_value); |
| 4708 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4709 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4710 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4711 | } |
| 4712 | |
| 4713 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4714 | codegen_->MarkGCCard( |
| 4715 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4716 | __ Bind(&done); |
| 4717 | |
| 4718 | if (slow_path != nullptr) { |
| 4719 | __ Bind(slow_path->GetExitLabel()); |
| 4720 | } |
| 4721 | |
| 4722 | break; |
| 4723 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4724 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4725 | case Primitive::kPrimInt: { |
| 4726 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4727 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4728 | if (value.IsRegister()) { |
| 4729 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4730 | } else { |
| 4731 | DCHECK(value.IsConstant()) << value; |
| 4732 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4733 | __ movl(address, Immediate(v)); |
| 4734 | } |
| 4735 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4736 | break; |
| 4737 | } |
| 4738 | |
| 4739 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4740 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4741 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4742 | if (value.IsRegister()) { |
| 4743 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4744 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4745 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4746 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4747 | Address address_high = |
| 4748 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4749 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4750 | } |
| 4751 | break; |
| 4752 | } |
| 4753 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4754 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4755 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4756 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4757 | if (value.IsFpuRegister()) { |
| 4758 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 4759 | } else { |
| 4760 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4761 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4762 | __ movl(address, Immediate(v)); |
| 4763 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4764 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4765 | break; |
| 4766 | } |
| 4767 | |
| 4768 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4769 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4770 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4771 | if (value.IsFpuRegister()) { |
| 4772 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 4773 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4774 | } else { |
| 4775 | int64_t v = |
| 4776 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4777 | Address address_high = |
| 4778 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4779 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 4780 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4781 | break; |
| 4782 | } |
| 4783 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4784 | case Primitive::kPrimVoid: |
| 4785 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4786 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4787 | } |
| 4788 | } |
| 4789 | |
| 4790 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4791 | LocationSummary* locations = |
| 4792 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4793 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 4794 | if (!instruction->IsEmittedAtUseSite()) { |
| 4795 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4796 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4797 | } |
| 4798 | |
| 4799 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 4800 | if (instruction->IsEmittedAtUseSite()) { |
| 4801 | return; |
| 4802 | } |
| 4803 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4804 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 4805 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4806 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4807 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4808 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4809 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4810 | } |
| 4811 | |
| 4812 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4813 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 4814 | InvokeRuntimeCallingConvention calling_convention; |
| 4815 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4816 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4817 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4818 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 4819 | HInstruction* length = instruction->InputAt(1); |
| 4820 | if (!length->IsEmittedAtUseSite()) { |
| 4821 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 4822 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4826 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4827 | Location index_loc = locations->InAt(0); |
| 4828 | Location length_loc = locations->InAt(1); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 4829 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4830 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4831 | if (length_loc.IsConstant()) { |
| 4832 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4833 | if (index_loc.IsConstant()) { |
| 4834 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4835 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4836 | if (index < 0 || index >= length) { |
| 4837 | codegen_->AddSlowPath(slow_path); |
| 4838 | __ jmp(slow_path->GetEntryLabel()); |
| 4839 | } else { |
| 4840 | // Some optimization after BCE may have generated this, and we should not |
| 4841 | // generate a bounds check if it is a valid range. |
| 4842 | } |
| 4843 | return; |
| 4844 | } |
| 4845 | |
| 4846 | // We have to reverse the jump condition because the length is the constant. |
| 4847 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4848 | __ cmpl(index_reg, Immediate(length)); |
| 4849 | codegen_->AddSlowPath(slow_path); |
| 4850 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4851 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 4852 | HInstruction* array_length = instruction->InputAt(1); |
| 4853 | if (array_length->IsEmittedAtUseSite()) { |
| 4854 | // Address the length field in the array. |
| 4855 | DCHECK(array_length->IsArrayLength()); |
| 4856 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 4857 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 4858 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 4859 | if (index_loc.IsConstant()) { |
| 4860 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4861 | __ cmpl(array_len, Immediate(value)); |
| 4862 | } else { |
| 4863 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 4864 | } |
| 4865 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4866 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4867 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4868 | } |
| 4869 | codegen_->AddSlowPath(slow_path); |
| 4870 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4871 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 4875 | CpuRegister card, |
| 4876 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4877 | CpuRegister value, |
| 4878 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4879 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4880 | if (value_can_be_null) { |
| 4881 | __ testl(value, value); |
| 4882 | __ j(kEqual, &is_null); |
| 4883 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4884 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4885 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4886 | __ movq(temp, object); |
| 4887 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4888 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4889 | if (value_can_be_null) { |
| 4890 | __ Bind(&is_null); |
| 4891 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4892 | } |
| 4893 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4894 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4895 | LOG(FATAL) << "Unimplemented"; |
| 4896 | } |
| 4897 | |
| 4898 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4899 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4900 | } |
| 4901 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4902 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4903 | LocationSummary* locations = |
| 4904 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4905 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4909 | HBasicBlock* block = instruction->GetBlock(); |
| 4910 | if (block->GetLoopInformation() != nullptr) { |
| 4911 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4912 | // The back edge will generate the suspend check. |
| 4913 | return; |
| 4914 | } |
| 4915 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4916 | // The goto will generate the suspend check. |
| 4917 | return; |
| 4918 | } |
| 4919 | GenerateSuspendCheck(instruction, nullptr); |
| 4920 | } |
| 4921 | |
| 4922 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4923 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4924 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4925 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 4926 | if (slow_path == nullptr) { |
| 4927 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 4928 | instruction->SetSlowPath(slow_path); |
| 4929 | codegen_->AddSlowPath(slow_path); |
| 4930 | if (successor != nullptr) { |
| 4931 | DCHECK(successor->IsLoopHeader()); |
| 4932 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4933 | } |
| 4934 | } else { |
| 4935 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4936 | } |
| 4937 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4938 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4939 | /* no_rip */ true), |
| 4940 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4941 | if (successor == nullptr) { |
| 4942 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4943 | __ Bind(slow_path->GetReturnLabel()); |
| 4944 | } else { |
| 4945 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4946 | __ jmp(slow_path->GetEntryLabel()); |
| 4947 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4948 | } |
| 4949 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4950 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 4951 | return codegen_->GetAssembler(); |
| 4952 | } |
| 4953 | |
| 4954 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4955 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4956 | Location source = move->GetSource(); |
| 4957 | Location destination = move->GetDestination(); |
| 4958 | |
| 4959 | if (source.IsRegister()) { |
| 4960 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4961 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4962 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4963 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4964 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4965 | } else { |
| 4966 | DCHECK(destination.IsDoubleStackSlot()); |
| 4967 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4968 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4969 | } |
| 4970 | } else if (source.IsStackSlot()) { |
| 4971 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4972 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4973 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4974 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4975 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4976 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4977 | } else { |
| 4978 | DCHECK(destination.IsStackSlot()); |
| 4979 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4980 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4981 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4982 | } else if (source.IsDoubleStackSlot()) { |
| 4983 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4984 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4985 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4986 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4987 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 4988 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4989 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 4990 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4991 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4992 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4993 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4994 | } else if (source.IsConstant()) { |
| 4995 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4996 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4997 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4998 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4999 | if (value == 0) { |
| 5000 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5001 | } else { |
| 5002 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5003 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5004 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5005 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5006 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5007 | } |
| 5008 | } else if (constant->IsLongConstant()) { |
| 5009 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5010 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5011 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5012 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5013 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5014 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5015 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5016 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5017 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5018 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5019 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5020 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5021 | } else { |
| 5022 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5023 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5024 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5025 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5026 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5027 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5028 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5029 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5030 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5031 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5032 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5033 | } else { |
| 5034 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5035 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5036 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5037 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5038 | } else if (source.IsFpuRegister()) { |
| 5039 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5040 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5041 | } else if (destination.IsStackSlot()) { |
| 5042 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5043 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5044 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5045 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5046 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5047 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5048 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5049 | } |
| 5050 | } |
| 5051 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5052 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5053 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5054 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5055 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5056 | } |
| 5057 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5058 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5059 | ScratchRegisterScope ensure_scratch( |
| 5060 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5061 | |
| 5062 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5063 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5064 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5065 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5066 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5067 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5068 | CpuRegister(ensure_scratch.GetRegister())); |
| 5069 | } |
| 5070 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5071 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5072 | __ movq(CpuRegister(TMP), reg1); |
| 5073 | __ movq(reg1, reg2); |
| 5074 | __ movq(reg2, CpuRegister(TMP)); |
| 5075 | } |
| 5076 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5077 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5078 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5079 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5080 | __ movq(reg, CpuRegister(TMP)); |
| 5081 | } |
| 5082 | |
| 5083 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5084 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5085 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5086 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5087 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5088 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5089 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5090 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5091 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5092 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5093 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5094 | } |
| 5095 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5096 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5097 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5098 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5099 | __ movd(reg, CpuRegister(TMP)); |
| 5100 | } |
| 5101 | |
| 5102 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5103 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5104 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5105 | __ movd(reg, CpuRegister(TMP)); |
| 5106 | } |
| 5107 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5108 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5109 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5110 | Location source = move->GetSource(); |
| 5111 | Location destination = move->GetDestination(); |
| 5112 | |
| 5113 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5114 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5115 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5116 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5117 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5118 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5119 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5120 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5121 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5122 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5123 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5124 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5125 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5126 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5127 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5128 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5129 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5130 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5131 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5132 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5133 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5134 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5135 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5136 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5137 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5138 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5139 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5140 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5141 | } |
| 5142 | } |
| 5143 | |
| 5144 | |
| 5145 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5146 | __ pushq(CpuRegister(reg)); |
| 5147 | } |
| 5148 | |
| 5149 | |
| 5150 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5151 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5152 | } |
| 5153 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5154 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5155 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5156 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5157 | Immediate(mirror::Class::kStatusInitialized)); |
| 5158 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5159 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5160 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5161 | } |
| 5162 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5163 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5164 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5165 | switch (desired_class_load_kind) { |
| 5166 | case HLoadClass::LoadKind::kReferrersClass: |
| 5167 | break; |
| 5168 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5169 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5170 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5171 | return HLoadClass::LoadKind::kBootImageLinkTimePcRelative; |
| 5172 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5173 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5174 | break; |
| 5175 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5176 | break; |
| 5177 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5178 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5179 | break; |
| 5180 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5181 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5182 | break; |
| 5183 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5184 | break; |
| 5185 | } |
| 5186 | return desired_class_load_kind; |
| 5187 | } |
| 5188 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5189 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5190 | if (cls->NeedsAccessCheck()) { |
| 5191 | InvokeRuntimeCallingConvention calling_convention; |
| 5192 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5193 | cls, |
| 5194 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5195 | Location::RegisterLocation(RAX), |
| 5196 | /* code_generator_supports_read_barrier */ true); |
| 5197 | return; |
| 5198 | } |
| 5199 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5200 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5201 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5202 | ? LocationSummary::kCallOnSlowPath |
| 5203 | : LocationSummary::kNoCall; |
| 5204 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5205 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5206 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5207 | } |
| 5208 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5209 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5210 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5211 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5212 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5213 | } |
| 5214 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5215 | } |
| 5216 | |
| 5217 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5218 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5219 | if (cls->NeedsAccessCheck()) { |
| 5220 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5221 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5222 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5223 | return; |
| 5224 | } |
| 5225 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5226 | Location out_loc = locations->Out(); |
| 5227 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5228 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5229 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5230 | bool generate_null_check = false; |
| 5231 | switch (cls->GetLoadKind()) { |
| 5232 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5233 | DCHECK(!cls->CanCallRuntime()); |
| 5234 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5235 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5236 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5237 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5238 | cls, |
| 5239 | out_loc, |
| 5240 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| 5241 | /*fixup_label*/nullptr, |
| 5242 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5243 | break; |
| 5244 | } |
| 5245 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5246 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5247 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5248 | codegen_->RecordTypePatch(cls); |
| 5249 | break; |
| 5250 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5251 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5252 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5253 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5254 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5255 | codegen_->RecordSimplePatch(); |
| 5256 | break; |
| 5257 | } |
| 5258 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5259 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5260 | // /* GcRoot<mirror::Class> */ out = *address |
| 5261 | if (IsUint<32>(cls->GetAddress())) { |
| 5262 | Address address = Address::Absolute(cls->GetAddress(), /* no_rip */ true); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5263 | GenerateGcRootFieldLoad(cls, |
| 5264 | out_loc, |
| 5265 | address, |
| 5266 | /*fixup_label*/nullptr, |
| 5267 | requires_read_barrier); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5268 | } else { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5269 | // TODO: Consider using opcode A1, i.e. movl eax, moff32 (with 64-bit address). |
| 5270 | __ movq(out, Immediate(cls->GetAddress())); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5271 | GenerateGcRootFieldLoad(cls, |
| 5272 | out_loc, |
| 5273 | Address(out, 0), |
| 5274 | /*fixup_label*/nullptr, |
| 5275 | requires_read_barrier); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5276 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5277 | generate_null_check = !cls->IsInDexCache(); |
| 5278 | break; |
| 5279 | } |
| 5280 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5281 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 5282 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 5283 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5284 | /* no_rip */ false); |
| 5285 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5286 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5287 | generate_null_check = !cls->IsInDexCache(); |
| 5288 | break; |
| 5289 | } |
| 5290 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5291 | // /* GcRoot<mirror::Class>[] */ out = |
| 5292 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5293 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5294 | __ movq(out, |
| 5295 | Address(current_method, |
| 5296 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
| 5297 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5298 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5299 | cls, |
| 5300 | out_loc, |
| 5301 | Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())), |
| 5302 | /*fixup_label*/nullptr, |
| 5303 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5304 | generate_null_check = !cls->IsInDexCache(); |
| 5305 | break; |
| 5306 | } |
| 5307 | default: |
| 5308 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5309 | UNREACHABLE(); |
| 5310 | } |
| 5311 | |
| 5312 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5313 | DCHECK(cls->CanCallRuntime()); |
| 5314 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5315 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5316 | codegen_->AddSlowPath(slow_path); |
| 5317 | if (generate_null_check) { |
| 5318 | __ testl(out, out); |
| 5319 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5320 | } |
| 5321 | if (cls->MustGenerateClinitCheck()) { |
| 5322 | GenerateClassInitializationCheck(slow_path, out); |
| 5323 | } else { |
| 5324 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5325 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5326 | } |
| 5327 | } |
| 5328 | |
| 5329 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5330 | LocationSummary* locations = |
| 5331 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5332 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5333 | if (check->HasUses()) { |
| 5334 | locations->SetOut(Location::SameAsFirstInput()); |
| 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5339 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5340 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5341 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5342 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5343 | GenerateClassInitializationCheck(slow_path, |
| 5344 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5345 | } |
| 5346 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5347 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5348 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5349 | switch (desired_string_load_kind) { |
| 5350 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5351 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5352 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5353 | return HLoadString::LoadKind::kBootImageLinkTimePcRelative; |
| 5354 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5355 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5356 | break; |
| 5357 | case HLoadString::LoadKind::kBootImageAddress: |
| 5358 | break; |
| 5359 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5360 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5361 | break; |
| 5362 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5363 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5364 | break; |
| 5365 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5366 | break; |
| 5367 | } |
| 5368 | return desired_string_load_kind; |
| 5369 | } |
| 5370 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5371 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5372 | LocationSummary::CallKind call_kind = load->NeedsEnvironment() |
| 5373 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5374 | : LocationSummary::kNoCall; |
| 5375 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5376 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 5377 | locations->SetInAt(0, Location::RequiresRegister()); |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 5378 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 5379 | } else { |
| 5380 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5381 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5385 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5386 | Location out_loc = locations->Out(); |
| 5387 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5388 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5389 | switch (load->GetLoadKind()) { |
| 5390 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5391 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5392 | codegen_->RecordStringPatch(load); |
| 5393 | return; // No dex cache slow path. |
| 5394 | } |
| 5395 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5396 | DCHECK_NE(load->GetAddress(), 0u); |
| 5397 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5398 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5399 | codegen_->RecordSimplePatch(); |
| 5400 | return; // No dex cache slow path. |
| 5401 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5402 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5403 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5404 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5405 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5406 | // 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] | 5407 | InvokeRuntimeCallingConvention calling_convention; |
| 5408 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 5409 | Immediate(load->GetStringIndex())); |
| 5410 | codegen_->InvokeRuntime(kQuickResolveString, |
| 5411 | load, |
| 5412 | load->GetDexPc()); |
| 5413 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5414 | } |
| 5415 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5416 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5417 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5418 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5419 | } |
| 5420 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5421 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5422 | LocationSummary* locations = |
| 5423 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5424 | locations->SetOut(Location::RequiresRegister()); |
| 5425 | } |
| 5426 | |
| 5427 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5428 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5429 | } |
| 5430 | |
| 5431 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5432 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5433 | } |
| 5434 | |
| 5435 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5436 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5440 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5441 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5442 | InvokeRuntimeCallingConvention calling_convention; |
| 5443 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5444 | } |
| 5445 | |
| 5446 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5447 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5448 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5449 | } |
| 5450 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5451 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5452 | return kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5453 | !kUseBakerReadBarrier && |
| 5454 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5455 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5456 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5457 | } |
| 5458 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5459 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5460 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5461 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5462 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5463 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5464 | case TypeCheckKind::kExactCheck: |
| 5465 | case TypeCheckKind::kAbstractClassCheck: |
| 5466 | case TypeCheckKind::kClassHierarchyCheck: |
| 5467 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5468 | call_kind = |
| 5469 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5470 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5471 | break; |
| 5472 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5473 | case TypeCheckKind::kUnresolvedCheck: |
| 5474 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5475 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5476 | break; |
| 5477 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5478 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5479 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5480 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5481 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5482 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5483 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5484 | locations->SetInAt(1, Location::Any()); |
| 5485 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5486 | locations->SetOut(Location::RequiresRegister()); |
| 5487 | // When read barriers are enabled, we need a temporary register for |
| 5488 | // some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5489 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5490 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5491 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5492 | } |
| 5493 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5494 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5495 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5496 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5497 | Location obj_loc = locations->InAt(0); |
| 5498 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5499 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5500 | Location out_loc = locations->Out(); |
| 5501 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5502 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5503 | locations->GetTemp(0) : |
| 5504 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5505 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5506 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5507 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5508 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5509 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5510 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5511 | |
| 5512 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5513 | // Avoid null check if we know obj is not null. |
| 5514 | if (instruction->MustDoNullCheck()) { |
| 5515 | __ testl(obj, obj); |
| 5516 | __ j(kEqual, &zero); |
| 5517 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5518 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5519 | // /* HeapReference<Class> */ out = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5520 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5521 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5522 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5523 | case TypeCheckKind::kExactCheck: { |
| 5524 | if (cls.IsRegister()) { |
| 5525 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5526 | } else { |
| 5527 | DCHECK(cls.IsStackSlot()) << cls; |
| 5528 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5529 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5530 | if (zero.IsLinked()) { |
| 5531 | // Classes must be equal for the instanceof to succeed. |
| 5532 | __ j(kNotEqual, &zero); |
| 5533 | __ movl(out, Immediate(1)); |
| 5534 | __ jmp(&done); |
| 5535 | } else { |
| 5536 | __ setcc(kEqual, out); |
| 5537 | // setcc only sets the low byte. |
| 5538 | __ andl(out, Immediate(1)); |
| 5539 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5540 | break; |
| 5541 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5542 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5543 | case TypeCheckKind::kAbstractClassCheck: { |
| 5544 | // If the class is abstract, we eagerly fetch the super class of the |
| 5545 | // object to avoid doing a comparison we know will fail. |
| 5546 | NearLabel loop, success; |
| 5547 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5548 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5549 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5550 | __ testl(out, out); |
| 5551 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5552 | __ j(kEqual, &done); |
| 5553 | if (cls.IsRegister()) { |
| 5554 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5555 | } else { |
| 5556 | DCHECK(cls.IsStackSlot()) << cls; |
| 5557 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5558 | } |
| 5559 | __ j(kNotEqual, &loop); |
| 5560 | __ movl(out, Immediate(1)); |
| 5561 | if (zero.IsLinked()) { |
| 5562 | __ jmp(&done); |
| 5563 | } |
| 5564 | break; |
| 5565 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5566 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5567 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5568 | // Walk over the class hierarchy to find a match. |
| 5569 | NearLabel loop, success; |
| 5570 | __ Bind(&loop); |
| 5571 | if (cls.IsRegister()) { |
| 5572 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5573 | } else { |
| 5574 | DCHECK(cls.IsStackSlot()) << cls; |
| 5575 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5576 | } |
| 5577 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5578 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5579 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5580 | __ testl(out, out); |
| 5581 | __ j(kNotEqual, &loop); |
| 5582 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5583 | __ jmp(&done); |
| 5584 | __ Bind(&success); |
| 5585 | __ movl(out, Immediate(1)); |
| 5586 | if (zero.IsLinked()) { |
| 5587 | __ jmp(&done); |
| 5588 | } |
| 5589 | break; |
| 5590 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5591 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5592 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5593 | // Do an exact check. |
| 5594 | NearLabel exact_check; |
| 5595 | if (cls.IsRegister()) { |
| 5596 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5597 | } else { |
| 5598 | DCHECK(cls.IsStackSlot()) << cls; |
| 5599 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5600 | } |
| 5601 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5602 | // 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] | 5603 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5604 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5605 | __ testl(out, out); |
| 5606 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5607 | __ j(kEqual, &done); |
| 5608 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5609 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5610 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5611 | __ movl(out, Immediate(1)); |
| 5612 | __ jmp(&done); |
| 5613 | break; |
| 5614 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5615 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5616 | case TypeCheckKind::kArrayCheck: { |
| 5617 | if (cls.IsRegister()) { |
| 5618 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5619 | } else { |
| 5620 | DCHECK(cls.IsStackSlot()) << cls; |
| 5621 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5622 | } |
| 5623 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5624 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5625 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5626 | codegen_->AddSlowPath(slow_path); |
| 5627 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5628 | __ movl(out, Immediate(1)); |
| 5629 | if (zero.IsLinked()) { |
| 5630 | __ jmp(&done); |
| 5631 | } |
| 5632 | break; |
| 5633 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5634 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5635 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5636 | case TypeCheckKind::kInterfaceCheck: { |
| 5637 | // 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] | 5638 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5639 | // cases. |
| 5640 | // |
| 5641 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5642 | // entry point without resorting to a type checking slow path |
| 5643 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5644 | // require to assign fixed registers for the inputs of this |
| 5645 | // HInstanceOf instruction (following the runtime calling |
| 5646 | // convention), which might be cluttered by the potential first |
| 5647 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5648 | // |
| 5649 | // TODO: Introduce a new runtime entry point taking the object |
| 5650 | // to test (instead of its class) as argument, and let it deal |
| 5651 | // with the read barrier issues. This will let us refactor this |
| 5652 | // case of the `switch` code as it was previously (with a direct |
| 5653 | // call to the runtime not using a type checking slow path). |
| 5654 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5655 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5656 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5657 | /* is_fatal */ false); |
| 5658 | codegen_->AddSlowPath(slow_path); |
| 5659 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5660 | if (zero.IsLinked()) { |
| 5661 | __ jmp(&done); |
| 5662 | } |
| 5663 | break; |
| 5664 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5665 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5666 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5667 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5668 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5669 | __ xorl(out, out); |
| 5670 | } |
| 5671 | |
| 5672 | if (done.IsLinked()) { |
| 5673 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5674 | } |
| 5675 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5676 | if (slow_path != nullptr) { |
| 5677 | __ Bind(slow_path->GetExitLabel()); |
| 5678 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5679 | } |
| 5680 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5681 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5682 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5683 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5684 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5685 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5686 | case TypeCheckKind::kExactCheck: |
| 5687 | case TypeCheckKind::kAbstractClassCheck: |
| 5688 | case TypeCheckKind::kClassHierarchyCheck: |
| 5689 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5690 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5691 | LocationSummary::kCallOnSlowPath : |
| 5692 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5693 | break; |
| 5694 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5695 | case TypeCheckKind::kUnresolvedCheck: |
| 5696 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5697 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5698 | break; |
| 5699 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5700 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5701 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5702 | locations->SetInAt(1, Location::Any()); |
| 5703 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 5704 | locations->AddTemp(Location::RequiresRegister()); |
| 5705 | // When read barriers are enabled, we need an additional temporary |
| 5706 | // register for some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5707 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5708 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5709 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5710 | } |
| 5711 | |
| 5712 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5713 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5714 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5715 | Location obj_loc = locations->InAt(0); |
| 5716 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5717 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5718 | Location temp_loc = locations->GetTemp(0); |
| 5719 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5720 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5721 | locations->GetTemp(1) : |
| 5722 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5723 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5724 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5725 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5726 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5727 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5728 | bool is_type_check_slow_path_fatal = |
| 5729 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5730 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5731 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5732 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5733 | !instruction->CanThrowIntoCatchBlock(); |
| 5734 | SlowPathCode* type_check_slow_path = |
| 5735 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5736 | is_type_check_slow_path_fatal); |
| 5737 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5738 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5739 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5740 | case TypeCheckKind::kExactCheck: |
| 5741 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5742 | NearLabel done; |
| 5743 | // Avoid null check if we know obj is not null. |
| 5744 | if (instruction->MustDoNullCheck()) { |
| 5745 | __ testl(obj, obj); |
| 5746 | __ j(kEqual, &done); |
| 5747 | } |
| 5748 | |
| 5749 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5750 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5751 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5752 | if (cls.IsRegister()) { |
| 5753 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5754 | } else { |
| 5755 | DCHECK(cls.IsStackSlot()) << cls; |
| 5756 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5757 | } |
| 5758 | // Jump to slow path for throwing the exception or doing a |
| 5759 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5760 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5761 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5762 | break; |
| 5763 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5764 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5765 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5766 | NearLabel done; |
| 5767 | // Avoid null check if we know obj is not null. |
| 5768 | if (instruction->MustDoNullCheck()) { |
| 5769 | __ testl(obj, obj); |
| 5770 | __ j(kEqual, &done); |
| 5771 | } |
| 5772 | |
| 5773 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5774 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5775 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5776 | // If the class is abstract, we eagerly fetch the super class of the |
| 5777 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5778 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5779 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5780 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5781 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5782 | |
| 5783 | // If the class reference currently in `temp` is not null, jump |
| 5784 | // to the `compare_classes` label to compare it with the checked |
| 5785 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5786 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5787 | __ j(kNotEqual, &compare_classes); |
| 5788 | // Otherwise, jump to the slow path to throw the exception. |
| 5789 | // |
| 5790 | // But before, move back the object's class into `temp` before |
| 5791 | // going into the slow path, as it has been overwritten in the |
| 5792 | // meantime. |
| 5793 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5794 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5795 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5796 | |
| 5797 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5798 | if (cls.IsRegister()) { |
| 5799 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5800 | } else { |
| 5801 | DCHECK(cls.IsStackSlot()) << cls; |
| 5802 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5803 | } |
| 5804 | __ j(kNotEqual, &loop); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5805 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5806 | break; |
| 5807 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5808 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5809 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5810 | NearLabel done; |
| 5811 | // Avoid null check if we know obj is not null. |
| 5812 | if (instruction->MustDoNullCheck()) { |
| 5813 | __ testl(obj, obj); |
| 5814 | __ j(kEqual, &done); |
| 5815 | } |
| 5816 | |
| 5817 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5818 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5819 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5820 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5821 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5822 | __ Bind(&loop); |
| 5823 | if (cls.IsRegister()) { |
| 5824 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5825 | } else { |
| 5826 | DCHECK(cls.IsStackSlot()) << cls; |
| 5827 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5828 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5829 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5830 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5831 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5832 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5833 | |
| 5834 | // If the class reference currently in `temp` is not null, jump |
| 5835 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5836 | __ testl(temp, temp); |
| 5837 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5838 | // Otherwise, jump to the slow path to throw the exception. |
| 5839 | // |
| 5840 | // But before, move back the object's class into `temp` before |
| 5841 | // going into the slow path, as it has been overwritten in the |
| 5842 | // meantime. |
| 5843 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5844 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5845 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5846 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5847 | break; |
| 5848 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5849 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5850 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5851 | // We cannot use a NearLabel here, as its range might be too |
| 5852 | // short in some cases when read barriers are enabled. This has |
| 5853 | // been observed for instance when the code emitted for this |
| 5854 | // case uses high x86-64 registers (R8-R15). |
| 5855 | Label done; |
| 5856 | // Avoid null check if we know obj is not null. |
| 5857 | if (instruction->MustDoNullCheck()) { |
| 5858 | __ testl(obj, obj); |
| 5859 | __ j(kEqual, &done); |
| 5860 | } |
| 5861 | |
| 5862 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5863 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5864 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5865 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5866 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5867 | if (cls.IsRegister()) { |
| 5868 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5869 | } else { |
| 5870 | DCHECK(cls.IsStackSlot()) << cls; |
| 5871 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5872 | } |
| 5873 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5874 | |
| 5875 | // 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] | 5876 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5877 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5878 | |
| 5879 | // If the component type is not null (i.e. the object is indeed |
| 5880 | // an array), jump to label `check_non_primitive_component_type` |
| 5881 | // to further check that this component type is not a primitive |
| 5882 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5883 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5884 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 5885 | // Otherwise, jump to the slow path to throw the exception. |
| 5886 | // |
| 5887 | // But before, move back the object's class into `temp` before |
| 5888 | // going into the slow path, as it has been overwritten in the |
| 5889 | // meantime. |
| 5890 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5891 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5892 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5893 | |
| 5894 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5895 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5896 | __ j(kEqual, &done); |
| 5897 | // Same comment as above regarding `temp` and the slow path. |
| 5898 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5899 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5900 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5901 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5902 | break; |
| 5903 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5904 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5905 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5906 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5907 | NearLabel done; |
| 5908 | // Avoid null check if we know obj is not null. |
| 5909 | if (instruction->MustDoNullCheck()) { |
| 5910 | __ testl(obj, obj); |
| 5911 | __ j(kEqual, &done); |
| 5912 | } |
| 5913 | |
| 5914 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5915 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5916 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5917 | // We always go into the type check slow path for the unresolved |
| 5918 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5919 | // |
| 5920 | // We cannot directly call the CheckCast runtime entry point |
| 5921 | // without resorting to a type checking slow path here (i.e. by |
| 5922 | // calling InvokeRuntime directly), as it would require to |
| 5923 | // assign fixed registers for the inputs of this HInstanceOf |
| 5924 | // instruction (following the runtime calling convention), which |
| 5925 | // might be cluttered by the potential first read barrier |
| 5926 | // emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5927 | // |
| 5928 | // TODO: Introduce a new runtime entry point taking the object |
| 5929 | // to test (instead of its class) as argument, and let it deal |
| 5930 | // with the read barrier issues. This will let us refactor this |
| 5931 | // case of the `switch` code as it was previously (with a direct |
| 5932 | // call to the runtime not using a type checking slow path). |
| 5933 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5934 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5935 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5936 | break; |
| 5937 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5938 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5939 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5940 | } |
| 5941 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5942 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5943 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5944 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5945 | InvokeRuntimeCallingConvention calling_convention; |
| 5946 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5947 | } |
| 5948 | |
| 5949 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5950 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5951 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5952 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5953 | if (instruction->IsEnter()) { |
| 5954 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5955 | } else { |
| 5956 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5957 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5958 | } |
| 5959 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5960 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5961 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5962 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5963 | |
| 5964 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5965 | LocationSummary* locations = |
| 5966 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5967 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5968 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5969 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5970 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5971 | locations->SetOut(Location::SameAsFirstInput()); |
| 5972 | } |
| 5973 | |
| 5974 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 5975 | HandleBitwiseOperation(instruction); |
| 5976 | } |
| 5977 | |
| 5978 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 5979 | HandleBitwiseOperation(instruction); |
| 5980 | } |
| 5981 | |
| 5982 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 5983 | HandleBitwiseOperation(instruction); |
| 5984 | } |
| 5985 | |
| 5986 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5987 | LocationSummary* locations = instruction->GetLocations(); |
| 5988 | Location first = locations->InAt(0); |
| 5989 | Location second = locations->InAt(1); |
| 5990 | DCHECK(first.Equals(locations->Out())); |
| 5991 | |
| 5992 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5993 | if (second.IsRegister()) { |
| 5994 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5995 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5996 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5997 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5998 | } else { |
| 5999 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6000 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6001 | } |
| 6002 | } else if (second.IsConstant()) { |
| 6003 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6004 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6005 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6006 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6007 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6008 | } else { |
| 6009 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6010 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6011 | } |
| 6012 | } else { |
| 6013 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6014 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6015 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6016 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6017 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6018 | } else { |
| 6019 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6020 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6021 | } |
| 6022 | } |
| 6023 | } else { |
| 6024 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6025 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6026 | bool second_is_constant = false; |
| 6027 | int64_t value = 0; |
| 6028 | if (second.IsConstant()) { |
| 6029 | second_is_constant = true; |
| 6030 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6031 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6032 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6033 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6034 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6035 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6036 | if (is_int32_value) { |
| 6037 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6038 | } else { |
| 6039 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6040 | } |
| 6041 | } else if (second.IsDoubleStackSlot()) { |
| 6042 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6043 | } else { |
| 6044 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6045 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6046 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6047 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6048 | if (is_int32_value) { |
| 6049 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6050 | } else { |
| 6051 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6052 | } |
| 6053 | } else if (second.IsDoubleStackSlot()) { |
| 6054 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6055 | } else { |
| 6056 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6057 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6058 | } else { |
| 6059 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6060 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6061 | if (is_int32_value) { |
| 6062 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6063 | } else { |
| 6064 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6065 | } |
| 6066 | } else if (second.IsDoubleStackSlot()) { |
| 6067 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6068 | } else { |
| 6069 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6070 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6071 | } |
| 6072 | } |
| 6073 | } |
| 6074 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6075 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6076 | Location out, |
| 6077 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6078 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6079 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6080 | if (kEmitCompilerReadBarrier) { |
| 6081 | if (kUseBakerReadBarrier) { |
| 6082 | // Load with fast path based Baker's read barrier. |
| 6083 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6084 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6085 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6086 | } else { |
| 6087 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6088 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6089 | // in the following move operation, as we will need it for the |
| 6090 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6091 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6092 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6093 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6094 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6095 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6096 | } |
| 6097 | } else { |
| 6098 | // Plain load with no read barrier. |
| 6099 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6100 | __ movl(out_reg, Address(out_reg, offset)); |
| 6101 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6102 | } |
| 6103 | } |
| 6104 | |
| 6105 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6106 | Location out, |
| 6107 | Location obj, |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6108 | uint32_t offset) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6109 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6110 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| 6111 | if (kEmitCompilerReadBarrier) { |
| 6112 | if (kUseBakerReadBarrier) { |
| 6113 | // Load with fast path based Baker's read barrier. |
| 6114 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6115 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6116 | instruction, out, obj_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. |
| 6119 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6120 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6121 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6122 | } |
| 6123 | } else { |
| 6124 | // Plain load with no read barrier. |
| 6125 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6126 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6127 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6128 | } |
| 6129 | } |
| 6130 | |
| 6131 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6132 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6133 | const Address& address, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6134 | Label* fixup_label, |
| 6135 | bool requires_read_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6136 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6137 | if (requires_read_barrier) { |
| 6138 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6139 | if (kUseBakerReadBarrier) { |
| 6140 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6141 | // Baker's read barrier are used: |
| 6142 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6143 | // root = *address; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6144 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6145 | // root = ReadBarrier::Mark(root) |
| 6146 | // } |
| 6147 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6148 | // /* GcRoot<mirror::Object> */ root = *address |
| 6149 | __ movl(root_reg, address); |
| 6150 | if (fixup_label != nullptr) { |
| 6151 | __ Bind(fixup_label); |
| 6152 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6153 | static_assert( |
| 6154 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6155 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6156 | "have different sizes."); |
| 6157 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6158 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6159 | "have different sizes."); |
| 6160 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6161 | // Slow path marking the GC root `root`. |
| 6162 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6163 | instruction, root, /* unpoison */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6164 | codegen_->AddSlowPath(slow_path); |
| 6165 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6166 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6167 | /* no_rip */ true), |
| 6168 | Immediate(0)); |
| 6169 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6170 | __ Bind(slow_path->GetExitLabel()); |
| 6171 | } else { |
| 6172 | // GC root loaded through a slow path for read barriers other |
| 6173 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6174 | // /* GcRoot<mirror::Object>* */ root = address |
| 6175 | __ leaq(root_reg, address); |
| 6176 | if (fixup_label != nullptr) { |
| 6177 | __ Bind(fixup_label); |
| 6178 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6179 | // /* mirror::Object* */ root = root->Read() |
| 6180 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6181 | } |
| 6182 | } else { |
| 6183 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6184 | // /* GcRoot<mirror::Object> */ root = *address |
| 6185 | __ movl(root_reg, address); |
| 6186 | if (fixup_label != nullptr) { |
| 6187 | __ Bind(fixup_label); |
| 6188 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6189 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6190 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6195 | Location ref, |
| 6196 | CpuRegister obj, |
| 6197 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6198 | bool needs_null_check) { |
| 6199 | DCHECK(kEmitCompilerReadBarrier); |
| 6200 | DCHECK(kUseBakerReadBarrier); |
| 6201 | |
| 6202 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6203 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6204 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6205 | } |
| 6206 | |
| 6207 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6208 | Location ref, |
| 6209 | CpuRegister obj, |
| 6210 | uint32_t data_offset, |
| 6211 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6212 | bool needs_null_check) { |
| 6213 | DCHECK(kEmitCompilerReadBarrier); |
| 6214 | DCHECK(kUseBakerReadBarrier); |
| 6215 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6216 | static_assert( |
| 6217 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6218 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6219 | // /* HeapReference<Object> */ ref = |
| 6220 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6221 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6222 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6226 | Location ref, |
| 6227 | CpuRegister obj, |
| 6228 | const Address& src, |
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 | // In slow path based read barriers, the read barrier call is |
| 6234 | // inserted after the original load. However, in fast path based |
| 6235 | // Baker's read barriers, we need to perform the load of |
| 6236 | // mirror::Object::monitor_ *before* the original reference load. |
| 6237 | // This load-load ordering is required by the read barrier. |
| 6238 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6239 | // |
| 6240 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6241 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6242 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6243 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6244 | // if (is_gray) { |
| 6245 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6246 | // } |
| 6247 | // |
| 6248 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6249 | // slightly more complex as: |
| 6250 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6251 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6252 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6253 | // 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] | 6254 | // - it performs additional checks that we do not do here for |
| 6255 | // performance reasons. |
| 6256 | |
| 6257 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6258 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6259 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6260 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 6261 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6262 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6263 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6264 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6265 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6266 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6267 | |
| 6268 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6269 | // ref = ReadBarrier::Mark(ref); |
| 6270 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6271 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6272 | if (needs_null_check) { |
| 6273 | MaybeRecordImplicitNullCheck(instruction); |
| 6274 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6275 | |
| 6276 | // Load fence to prevent load-load reordering. |
| 6277 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6278 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6279 | |
| 6280 | // The actual reference load. |
| 6281 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6282 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6283 | |
| 6284 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6285 | // Slow path marking the object `ref` when it is gray. |
| 6286 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6287 | instruction, ref, /* unpoison */ true); |
| 6288 | AddSlowPath(slow_path); |
| 6289 | |
| 6290 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6291 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6292 | |
| 6293 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6294 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6295 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6296 | __ Bind(slow_path->GetExitLabel()); |
| 6297 | } |
| 6298 | |
| 6299 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6300 | Location out, |
| 6301 | Location ref, |
| 6302 | Location obj, |
| 6303 | uint32_t offset, |
| 6304 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6305 | DCHECK(kEmitCompilerReadBarrier); |
| 6306 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6307 | // Insert a slow path based read barrier *after* the reference load. |
| 6308 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6309 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6310 | // reference will be carried out by the runtime within the slow |
| 6311 | // path. |
| 6312 | // |
| 6313 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6314 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6315 | // not used by the artReadBarrierSlow entry point. |
| 6316 | // |
| 6317 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6318 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6319 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6320 | AddSlowPath(slow_path); |
| 6321 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6322 | __ jmp(slow_path->GetEntryLabel()); |
| 6323 | __ Bind(slow_path->GetExitLabel()); |
| 6324 | } |
| 6325 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6326 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6327 | Location out, |
| 6328 | Location ref, |
| 6329 | Location obj, |
| 6330 | uint32_t offset, |
| 6331 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6332 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6333 | // Baker's read barriers shall be handled by the fast path |
| 6334 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6335 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6336 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6337 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6338 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6339 | } else if (kPoisonHeapReferences) { |
| 6340 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6341 | } |
| 6342 | } |
| 6343 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6344 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6345 | Location out, |
| 6346 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6347 | DCHECK(kEmitCompilerReadBarrier); |
| 6348 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6349 | // Insert a slow path based read barrier *after* the GC root load. |
| 6350 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6351 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6352 | // not need to do anything special for this here. |
| 6353 | SlowPathCode* slow_path = |
| 6354 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6355 | AddSlowPath(slow_path); |
| 6356 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6357 | __ jmp(slow_path->GetEntryLabel()); |
| 6358 | __ Bind(slow_path->GetExitLabel()); |
| 6359 | } |
| 6360 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6361 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6362 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6363 | LOG(FATAL) << "Unreachable"; |
| 6364 | } |
| 6365 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6366 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6367 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6368 | LOG(FATAL) << "Unreachable"; |
| 6369 | } |
| 6370 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6371 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6372 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6373 | LocationSummary* locations = |
| 6374 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6375 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6376 | locations->AddTemp(Location::RequiresRegister()); |
| 6377 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6378 | } |
| 6379 | |
| 6380 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6381 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6382 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6383 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6384 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6385 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6386 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6387 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6388 | |
| 6389 | // Should we generate smaller inline compare/jumps? |
| 6390 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6391 | // Figure out the correct compare values and jump conditions. |
| 6392 | // Handle the first compare/branch as a special case because it might |
| 6393 | // jump to the default case. |
| 6394 | DCHECK_GT(num_entries, 2u); |
| 6395 | Condition first_condition; |
| 6396 | uint32_t index; |
| 6397 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6398 | if (lower_bound != 0) { |
| 6399 | first_condition = kLess; |
| 6400 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6401 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6402 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6403 | |
| 6404 | index = 1; |
| 6405 | } else { |
| 6406 | // Handle all the compare/jumps below. |
| 6407 | first_condition = kBelow; |
| 6408 | index = 0; |
| 6409 | } |
| 6410 | |
| 6411 | // Handle the rest of the compare/jumps. |
| 6412 | for (; index + 1 < num_entries; index += 2) { |
| 6413 | int32_t compare_to_value = lower_bound + index + 1; |
| 6414 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6415 | // Jump to successors[index] if value < case_value[index]. |
| 6416 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6417 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6418 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6419 | } |
| 6420 | |
| 6421 | if (index != num_entries) { |
| 6422 | // There are an odd number of entries. Handle the last one. |
| 6423 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6424 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6425 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6426 | } |
| 6427 | |
| 6428 | // And the default for any other value. |
| 6429 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6430 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6431 | } |
| 6432 | return; |
| 6433 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6434 | |
| 6435 | // Remove the bias, if needed. |
| 6436 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6437 | if (lower_bound != 0) { |
| 6438 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6439 | value_reg_out = temp_reg.AsRegister(); |
| 6440 | } |
| 6441 | CpuRegister value_reg(value_reg_out); |
| 6442 | |
| 6443 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6444 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6445 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6446 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6447 | // We are in the range of the table. |
| 6448 | // Load the address of the jump table in the constant area. |
| 6449 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6450 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6451 | // Load the (signed) offset from the jump table. |
| 6452 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6453 | |
| 6454 | // Add the offset to the address of the table base. |
| 6455 | __ addq(temp_reg, base_reg); |
| 6456 | |
| 6457 | // And jump. |
| 6458 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6459 | } |
| 6460 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6461 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6462 | if (value == 0) { |
| 6463 | __ xorl(dest, dest); |
| 6464 | } else { |
| 6465 | __ movl(dest, Immediate(value)); |
| 6466 | } |
| 6467 | } |
| 6468 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6469 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6470 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6471 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6472 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6473 | } else if (IsUint<32>(value)) { |
| 6474 | // 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] | 6475 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6476 | } else { |
| 6477 | __ movq(dest, Immediate(value)); |
| 6478 | } |
| 6479 | } |
| 6480 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6481 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6482 | if (value == 0) { |
| 6483 | __ xorps(dest, dest); |
| 6484 | } else { |
| 6485 | __ movss(dest, LiteralInt32Address(value)); |
| 6486 | } |
| 6487 | } |
| 6488 | |
| 6489 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6490 | if (value == 0) { |
| 6491 | __ xorpd(dest, dest); |
| 6492 | } else { |
| 6493 | __ movsd(dest, LiteralInt64Address(value)); |
| 6494 | } |
| 6495 | } |
| 6496 | |
| 6497 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6498 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6499 | } |
| 6500 | |
| 6501 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6502 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6503 | } |
| 6504 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6505 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6506 | if (value == 0) { |
| 6507 | __ testl(dest, dest); |
| 6508 | } else { |
| 6509 | __ cmpl(dest, Immediate(value)); |
| 6510 | } |
| 6511 | } |
| 6512 | |
| 6513 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6514 | if (IsInt<32>(value)) { |
| 6515 | if (value == 0) { |
| 6516 | __ testq(dest, dest); |
| 6517 | } else { |
| 6518 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6519 | } |
| 6520 | } else { |
| 6521 | // Value won't fit in an int. |
| 6522 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6523 | } |
| 6524 | } |
| 6525 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6526 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 6527 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 6528 | if (rhs.IsConstant()) { |
| 6529 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 6530 | Compare32BitValue(lhs_reg, value); |
| 6531 | } else if (rhs.IsStackSlot()) { |
| 6532 | __ cmpl(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 6533 | } else { |
| 6534 | __ cmpl(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 6535 | } |
| 6536 | } |
| 6537 | |
| 6538 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 6539 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 6540 | if (rhs.IsConstant()) { |
| 6541 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 6542 | Compare64BitValue(lhs_reg, value); |
| 6543 | } else if (rhs.IsDoubleStackSlot()) { |
| 6544 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 6545 | } else { |
| 6546 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 6547 | } |
| 6548 | } |
| 6549 | |
| 6550 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 6551 | Location index, |
| 6552 | ScaleFactor scale, |
| 6553 | uint32_t data_offset) { |
| 6554 | return index.IsConstant() ? |
| 6555 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 6556 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 6557 | } |
| 6558 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6559 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6560 | DCHECK(dest.IsDoubleStackSlot()); |
| 6561 | if (IsInt<32>(value)) { |
| 6562 | // Can move directly as an int32 constant. |
| 6563 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6564 | Immediate(static_cast<int32_t>(value))); |
| 6565 | } else { |
| 6566 | Load64BitValue(CpuRegister(TMP), value); |
| 6567 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6568 | } |
| 6569 | } |
| 6570 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6571 | /** |
| 6572 | * Class to handle late fixup of offsets into constant area. |
| 6573 | */ |
| 6574 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6575 | public: |
| 6576 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6577 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6578 | |
| 6579 | protected: |
| 6580 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6581 | |
| 6582 | CodeGeneratorX86_64* codegen_; |
| 6583 | |
| 6584 | private: |
| 6585 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6586 | // Patch the correct offset for the instruction. We use the address of the |
| 6587 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6588 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6589 | int32_t relative_position = constant_offset - pos; |
| 6590 | |
| 6591 | // Patch in the right value. |
| 6592 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6593 | } |
| 6594 | |
| 6595 | // Location in constant area that the fixup refers to. |
| 6596 | size_t offset_into_constant_area_; |
| 6597 | }; |
| 6598 | |
| 6599 | /** |
| 6600 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6601 | * constant area. |
| 6602 | */ |
| 6603 | class JumpTableRIPFixup : public RIPFixup { |
| 6604 | public: |
| 6605 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6606 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6607 | |
| 6608 | void CreateJumpTable() { |
| 6609 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6610 | |
| 6611 | // Ensure that the reference to the jump table has the correct offset. |
| 6612 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6613 | SetOffset(offset_in_constant_table); |
| 6614 | |
| 6615 | // Compute the offset from the start of the function to this jump table. |
| 6616 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6617 | |
| 6618 | // Populate the jump table with the correct values for the jump table. |
| 6619 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6620 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6621 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6622 | // The value that we want is the target offset - the position of the table. |
| 6623 | for (int32_t i = 0; i < num_entries; i++) { |
| 6624 | HBasicBlock* b = successors[i]; |
| 6625 | Label* l = codegen_->GetLabelOf(b); |
| 6626 | DCHECK(l->IsBound()); |
| 6627 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 6628 | assembler->AppendInt32(offset_to_block); |
| 6629 | } |
| 6630 | } |
| 6631 | |
| 6632 | private: |
| 6633 | const HPackedSwitch* switch_instr_; |
| 6634 | }; |
| 6635 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6636 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 6637 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6638 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6639 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6640 | // 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] | 6641 | assembler->Align(4, 0); |
| 6642 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6643 | |
| 6644 | // Populate any jump tables. |
| 6645 | for (auto jump_table : fixups_to_jump_tables_) { |
| 6646 | jump_table->CreateJumpTable(); |
| 6647 | } |
| 6648 | |
| 6649 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6650 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6651 | } |
| 6652 | |
| 6653 | // And finish up. |
| 6654 | CodeGenerator::Finalize(allocator); |
| 6655 | } |
| 6656 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6657 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 6658 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 6659 | return Address::RIP(fixup); |
| 6660 | } |
| 6661 | |
| 6662 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 6663 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 6664 | return Address::RIP(fixup); |
| 6665 | } |
| 6666 | |
| 6667 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 6668 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 6669 | return Address::RIP(fixup); |
| 6670 | } |
| 6671 | |
| 6672 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 6673 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 6674 | return Address::RIP(fixup); |
| 6675 | } |
| 6676 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6677 | // TODO: trg as memory. |
| 6678 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6679 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6680 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6681 | return; |
| 6682 | } |
| 6683 | |
| 6684 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6685 | |
| 6686 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 6687 | if (trg.Equals(return_loc)) { |
| 6688 | return; |
| 6689 | } |
| 6690 | |
| 6691 | // Let the parallel move resolver take care of all of this. |
| 6692 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6693 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6694 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6695 | } |
| 6696 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6697 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 6698 | // Create a fixup to be used to create and address the jump table. |
| 6699 | JumpTableRIPFixup* table_fixup = |
| 6700 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 6701 | |
| 6702 | // We have to populate the jump tables. |
| 6703 | fixups_to_jump_tables_.push_back(table_fixup); |
| 6704 | return Address::RIP(table_fixup); |
| 6705 | } |
| 6706 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 6707 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 6708 | const Address& addr_high, |
| 6709 | int64_t v, |
| 6710 | HInstruction* instruction) { |
| 6711 | if (IsInt<32>(v)) { |
| 6712 | int32_t v_32 = v; |
| 6713 | __ movq(addr_low, Immediate(v_32)); |
| 6714 | MaybeRecordImplicitNullCheck(instruction); |
| 6715 | } else { |
| 6716 | // Didn't fit in a register. Do it in pieces. |
| 6717 | int32_t low_v = Low32Bits(v); |
| 6718 | int32_t high_v = High32Bits(v); |
| 6719 | __ movl(addr_low, Immediate(low_v)); |
| 6720 | MaybeRecordImplicitNullCheck(instruction); |
| 6721 | __ movl(addr_high, Immediate(high_v)); |
| 6722 | } |
| 6723 | } |
| 6724 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6725 | #undef __ |
| 6726 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6727 | } // namespace x86_64 |
| 6728 | } // namespace art |