| 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" |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 20 | #include "class_table.h" |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 25 | #include "gc/space/image_space.h" |
| Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 26 | #include "heap_poisoning.h" |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_x86_64.h" |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 29 | #include "linker/linker_patch.h" |
| Andreas Gampe | d490129 | 2017-05-30 18:41:34 -0700 | [diff] [blame] | 30 | #include "lock_word.h" |
| Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 31 | #include "mirror/array-inl.h" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 32 | #include "mirror/class-inl.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 33 | #include "mirror/object_reference.h" |
| 34 | #include "thread.h" |
| 35 | #include "utils/assembler.h" |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 36 | #include "utils/stack_checks.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 37 | #include "utils/x86_64/assembler_x86_64.h" |
| 38 | #include "utils/x86_64/managed_register_x86_64.h" |
| 39 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 40 | namespace art { |
| 41 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 42 | template<class MirrorType> |
| 43 | class GcRoot; |
| 44 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 45 | namespace x86_64 { |
| 46 | |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = RDI; |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 49 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 50 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 51 | // generates less code/data with a small num_entries. |
| 52 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 53 | |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 54 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 55 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 56 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 57 | static constexpr int kC2ConditionMask = 0x400; |
| 58 | |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 59 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 60 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 61 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 62 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 63 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 65 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 66 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 67 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 68 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 70 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 71 | // Live registers will be restored in the catch block if caught. |
| 72 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 73 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 74 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 75 | instruction_, |
| 76 | instruction_->GetDexPc(), |
| 77 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 78 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 81 | bool IsFatal() const OVERRIDE { return true; } |
| 82 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 83 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 84 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 85 | private: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 86 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 87 | }; |
| 88 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 89 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 91 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 92 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 93 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 94 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | __ Bind(GetEntryLabel()); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 96 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 97 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 100 | bool IsFatal() const OVERRIDE { return true; } |
| 101 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 102 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 103 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | private: |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 106 | }; |
| 107 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 108 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 110 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, DataType::Type type, bool is_div) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 111 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 113 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 114 | __ Bind(GetEntryLabel()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 115 | if (type_ == DataType::Type::kInt32) { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 116 | if (is_div_) { |
| 117 | __ negl(cpu_reg_); |
| 118 | } else { |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 119 | __ xorl(cpu_reg_, cpu_reg_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 122 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 123 | DCHECK_EQ(DataType::Type::kInt64, type_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 124 | if (is_div_) { |
| 125 | __ negq(cpu_reg_); |
| 126 | } else { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 127 | __ xorl(cpu_reg_, cpu_reg_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 128 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 129 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 130 | __ jmp(GetExitLabel()); |
| 131 | } |
| 132 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 133 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 134 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 135 | private: |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 136 | const CpuRegister cpu_reg_; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 137 | const DataType::Type type_; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 138 | const bool is_div_; |
| 139 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 142 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 143 | public: |
| Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 144 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 145 | : SlowPathCode(instruction), successor_(successor) {} |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 146 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 147 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 148 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 149 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 150 | __ Bind(GetEntryLabel()); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 151 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 152 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 153 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 154 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 155 | if (successor_ == nullptr) { |
| 156 | __ jmp(GetReturnLabel()); |
| 157 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 158 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 159 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 162 | Label* GetReturnLabel() { |
| 163 | DCHECK(successor_ == nullptr); |
| 164 | return &return_label_; |
| 165 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 166 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 167 | HBasicBlock* GetSuccessor() const { |
| 168 | return successor_; |
| 169 | } |
| 170 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 171 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 172 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 173 | private: |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 174 | HBasicBlock* const successor_; |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 175 | Label return_label_; |
| 176 | |
| 177 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 178 | }; |
| 179 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 180 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 181 | public: |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 182 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 183 | : SlowPathCode(instruction) {} |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 184 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 185 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 186 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 187 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 188 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 189 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 190 | // Live registers will be restored in the catch block if caught. |
| 191 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 192 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 193 | // Are we using an array length from memory? |
| 194 | HInstruction* array_length = instruction_->InputAt(1); |
| 195 | Location length_loc = locations->InAt(1); |
| 196 | InvokeRuntimeCallingConvention calling_convention; |
| 197 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 198 | // Load the array length into our temporary. |
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 199 | HArrayLength* length = array_length->AsArrayLength(); |
| Nicolas Geoffray | 003444a | 2017-10-17 10:58:42 +0100 | [diff] [blame] | 200 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 201 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 202 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 203 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 204 | // Check for conflicts with index. |
| 205 | if (length_loc.Equals(locations->InAt(0))) { |
| 206 | // We know we aren't using parameter 2. |
| 207 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 208 | } |
| 209 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 210 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 211 | __ shrl(length_loc.AsRegister<CpuRegister>(), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 212 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 213 | } |
| 214 | |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 215 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 216 | // move resolver. |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 217 | codegen->EmitParallelMoves( |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 218 | locations->InAt(0), |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 219 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 220 | DataType::Type::kInt32, |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 221 | length_loc, |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 222 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 223 | DataType::Type::kInt32); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 224 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 225 | ? kQuickThrowStringBounds |
| 226 | : kQuickThrowArrayBounds; |
| 227 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 228 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 229 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 230 | } |
| 231 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 232 | bool IsFatal() const OVERRIDE { return true; } |
| 233 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 234 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 235 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 236 | private: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 237 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 238 | }; |
| 239 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 240 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 241 | public: |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame^] | 242 | LoadClassSlowPathX86_64(HLoadClass* cls, HInstruction* at) |
| 243 | : SlowPathCode(at), cls_(cls) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame^] | 245 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 246 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 247 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 248 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 249 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame^] | 250 | Location out = locations->Out(); |
| 251 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 252 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 253 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 254 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 255 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 256 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 257 | SaveLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 258 | |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 259 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame^] | 260 | if (must_resolve_type) { |
| 261 | DCHECK(IsSameDexFile(cls_->GetDexFile(), x86_64_codegen->GetGraph()->GetDexFile())); |
| 262 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 263 | __ movl(CpuRegister(RAX), Immediate(type_index.index_)); |
| 264 | x86_64_codegen->InvokeRuntime(kQuickInitializeType, instruction_, dex_pc, this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 265 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame^] | 266 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 267 | } else { |
| 268 | DCHECK(must_do_clinit); |
| 269 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 270 | x86_64_codegen->Move(Location::RegisterLocation(RAX), source); |
| 271 | } |
| 272 | if (must_do_clinit) { |
| 273 | x86_64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 274 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 275 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 276 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 277 | // Move the class to the desired location. |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 278 | if (out.IsValid()) { |
| 279 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 280 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 283 | RestoreLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 284 | __ jmp(GetExitLabel()); |
| 285 | } |
| 286 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 287 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 288 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 289 | private: |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 290 | // The class this slow path will load. |
| 291 | HLoadClass* const cls_; |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 292 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 293 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 294 | }; |
| 295 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 296 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
| 297 | public: |
| 298 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
| 299 | |
| 300 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 301 | LocationSummary* locations = instruction_->GetLocations(); |
| 302 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 303 | |
| 304 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 305 | __ Bind(GetEntryLabel()); |
| 306 | SaveLiveRegisters(codegen, locations); |
| 307 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 308 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 309 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 310 | __ movl(CpuRegister(RAX), Immediate(string_index.index_)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 311 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
| 312 | instruction_, |
| 313 | instruction_->GetDexPc(), |
| 314 | this); |
| 315 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 316 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 317 | RestoreLiveRegisters(codegen, locations); |
| 318 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 319 | __ jmp(GetExitLabel()); |
| 320 | } |
| 321 | |
| 322 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 323 | |
| 324 | private: |
| 325 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 326 | }; |
| 327 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 328 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | public: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 330 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 331 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 332 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 333 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 334 | LocationSummary* locations = instruction_->GetLocations(); |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 335 | uint32_t dex_pc = instruction_->GetDexPc(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 336 | DCHECK(instruction_->IsCheckCast() |
| 337 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 338 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 339 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 340 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 341 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 342 | if (kPoisonHeapReferences && |
| 343 | instruction_->IsCheckCast() && |
| 344 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 345 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 346 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<CpuRegister>()); |
| 347 | } |
| 348 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 349 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 350 | SaveLiveRegisters(codegen, locations); |
| 351 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 352 | |
| 353 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 354 | // move resolver. |
| 355 | InvokeRuntimeCallingConvention calling_convention; |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 356 | codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 357 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 358 | DataType::Type::kReference, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 359 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 360 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 361 | DataType::Type::kReference); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 362 | if (instruction_->IsInstanceOf()) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 363 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 364 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 365 | } else { |
| 366 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 367 | x86_64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 368 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 369 | } |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 370 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 371 | if (!is_fatal_) { |
| 372 | if (instruction_->IsInstanceOf()) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 373 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 374 | } |
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 375 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 376 | RestoreLiveRegisters(codegen, locations); |
| 377 | __ jmp(GetExitLabel()); |
| 378 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 381 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 382 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 383 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 384 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 385 | private: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 386 | const bool is_fatal_; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 387 | |
| 388 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 389 | }; |
| 390 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 391 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 392 | public: |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 393 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 394 | : SlowPathCode(instruction) {} |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 395 | |
| 396 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 397 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 398 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 399 | LocationSummary* locations = instruction_->GetLocations(); |
| 400 | SaveLiveRegisters(codegen, locations); |
| 401 | InvokeRuntimeCallingConvention calling_convention; |
| 402 | x86_64_codegen->Load32BitValue( |
| 403 | CpuRegister(calling_convention.GetRegisterAt(0)), |
| 404 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 405 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 406 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 409 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 410 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 411 | private: |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 412 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 413 | }; |
| 414 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 415 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 416 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 417 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 418 | |
| 419 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 420 | LocationSummary* locations = instruction_->GetLocations(); |
| 421 | __ Bind(GetEntryLabel()); |
| 422 | SaveLiveRegisters(codegen, locations); |
| 423 | |
| 424 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 425 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 426 | parallel_move.AddMove( |
| 427 | locations->InAt(0), |
| 428 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 429 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 430 | nullptr); |
| 431 | parallel_move.AddMove( |
| 432 | locations->InAt(1), |
| 433 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 434 | DataType::Type::kInt32, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 435 | nullptr); |
| 436 | parallel_move.AddMove( |
| 437 | locations->InAt(2), |
| 438 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 439 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 440 | nullptr); |
| 441 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 442 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 443 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 444 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 445 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 446 | RestoreLiveRegisters(codegen, locations); |
| 447 | __ jmp(GetExitLabel()); |
| 448 | } |
| 449 | |
| 450 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 451 | |
| 452 | private: |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 453 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 454 | }; |
| 455 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 456 | // Slow path marking an object reference `ref` during a read |
| 457 | // barrier. The field `obj.field` in the object `obj` holding this |
| 458 | // reference does not get updated by this slow path after marking (see |
| 459 | // ReadBarrierMarkAndUpdateFieldSlowPathX86_64 below for that). |
| 460 | // |
| 461 | // This means that after the execution of this slow path, `ref` will |
| 462 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 463 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 464 | // probably still be a from-space reference (unless it gets updated by |
| 465 | // another thread, or if another thread installed another object |
| 466 | // reference (different from `ref`) in `obj.field`). |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 467 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 468 | public: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 469 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, |
| 470 | Location ref, |
| 471 | bool unpoison_ref_before_marking) |
| 472 | : SlowPathCode(instruction), |
| 473 | ref_(ref), |
| 474 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 475 | DCHECK(kEmitCompilerReadBarrier); |
| 476 | } |
| 477 | |
| 478 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 479 | |
| 480 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 481 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 482 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 483 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 484 | DCHECK(locations->CanCall()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 485 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 486 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 487 | instruction_->IsStaticFieldGet() || |
| 488 | instruction_->IsArrayGet() || |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 489 | instruction_->IsArraySet() || |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 490 | instruction_->IsLoadClass() || |
| 491 | instruction_->IsLoadString() || |
| 492 | instruction_->IsInstanceOf() || |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 493 | instruction_->IsCheckCast() || |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 494 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 495 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 496 | << "Unexpected instruction in read barrier marking slow path: " |
| 497 | << instruction_->DebugName(); |
| 498 | |
| 499 | __ Bind(GetEntryLabel()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 500 | if (unpoison_ref_before_marking_) { |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 501 | // Object* ref = ref_addr->AsMirrorPtr() |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 502 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 503 | } |
| Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 504 | // No need to save live registers; it's taken care of by the |
| 505 | // entrypoint. Also, there is no need to update the stack mask, |
| 506 | // as this runtime call will not trigger a garbage collection. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 507 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 508 | DCHECK_NE(ref_reg, RSP); |
| 509 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 510 | // "Compact" slow path, saving two moves. |
| 511 | // |
| 512 | // Instead of using the standard runtime calling convention (input |
| 513 | // and output in R0): |
| 514 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 515 | // RDI <- ref |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 516 | // RAX <- ReadBarrierMark(RDI) |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 517 | // ref <- RAX |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 518 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 519 | // we just use rX (the register containing `ref`) as input and output |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 520 | // of a dedicated entrypoint: |
| 521 | // |
| 522 | // rX <- ReadBarrierMarkRegX(rX) |
| 523 | // |
| 524 | int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 525 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 526 | // This runtime call does not require a stack map. |
| 527 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 528 | __ jmp(GetExitLabel()); |
| 529 | } |
| 530 | |
| 531 | private: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 532 | // The location (register) of the marked object reference. |
| 533 | const Location ref_; |
| 534 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 535 | const bool unpoison_ref_before_marking_; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 536 | |
| 537 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 538 | }; |
| 539 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 540 | // Slow path marking an object reference `ref` during a read barrier, |
| 541 | // and if needed, atomically updating the field `obj.field` in the |
| 542 | // object `obj` holding this reference after marking (contrary to |
| 543 | // ReadBarrierMarkSlowPathX86_64 above, which never tries to update |
| 544 | // `obj.field`). |
| 545 | // |
| 546 | // This means that after the execution of this slow path, both `ref` |
| 547 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 548 | // hold the same to-space reference (unless another thread installed |
| 549 | // another object reference (different from `ref`) in `obj.field`). |
| 550 | class ReadBarrierMarkAndUpdateFieldSlowPathX86_64 : public SlowPathCode { |
| 551 | public: |
| 552 | ReadBarrierMarkAndUpdateFieldSlowPathX86_64(HInstruction* instruction, |
| 553 | Location ref, |
| 554 | CpuRegister obj, |
| 555 | const Address& field_addr, |
| 556 | bool unpoison_ref_before_marking, |
| 557 | CpuRegister temp1, |
| 558 | CpuRegister temp2) |
| 559 | : SlowPathCode(instruction), |
| 560 | ref_(ref), |
| 561 | obj_(obj), |
| 562 | field_addr_(field_addr), |
| 563 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 564 | temp1_(temp1), |
| 565 | temp2_(temp2) { |
| 566 | DCHECK(kEmitCompilerReadBarrier); |
| 567 | } |
| 568 | |
| 569 | const char* GetDescription() const OVERRIDE { |
| 570 | return "ReadBarrierMarkAndUpdateFieldSlowPathX86_64"; |
| 571 | } |
| 572 | |
| 573 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 574 | LocationSummary* locations = instruction_->GetLocations(); |
| 575 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 576 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| 577 | DCHECK(locations->CanCall()); |
| 578 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 579 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 580 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 581 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 582 | << instruction_->DebugName(); |
| 583 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 584 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 585 | |
| 586 | __ Bind(GetEntryLabel()); |
| 587 | if (unpoison_ref_before_marking_) { |
| 588 | // Object* ref = ref_addr->AsMirrorPtr() |
| 589 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| 590 | } |
| 591 | |
| 592 | // Save the old (unpoisoned) reference. |
| 593 | __ movl(temp1_, ref_cpu_reg); |
| 594 | |
| 595 | // No need to save live registers; it's taken care of by the |
| 596 | // entrypoint. Also, there is no need to update the stack mask, |
| 597 | // as this runtime call will not trigger a garbage collection. |
| 598 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 599 | DCHECK_NE(ref_reg, RSP); |
| 600 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 601 | // "Compact" slow path, saving two moves. |
| 602 | // |
| 603 | // Instead of using the standard runtime calling convention (input |
| 604 | // and output in R0): |
| 605 | // |
| 606 | // RDI <- ref |
| 607 | // RAX <- ReadBarrierMark(RDI) |
| 608 | // ref <- RAX |
| 609 | // |
| 610 | // we just use rX (the register containing `ref`) as input and output |
| 611 | // of a dedicated entrypoint: |
| 612 | // |
| 613 | // rX <- ReadBarrierMarkRegX(rX) |
| 614 | // |
| 615 | int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 616 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 617 | // This runtime call does not require a stack map. |
| 618 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 619 | |
| 620 | // If the new reference is different from the old reference, |
| 621 | // update the field in the holder (`*field_addr`). |
| 622 | // |
| 623 | // Note that this field could also hold a different object, if |
| 624 | // another thread had concurrently changed it. In that case, the |
| 625 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 626 | // operation below would abort the CAS, leaving the field as-is. |
| 627 | NearLabel done; |
| 628 | __ cmpl(temp1_, ref_cpu_reg); |
| 629 | __ j(kEqual, &done); |
| 630 | |
| 631 | // Update the the holder's field atomically. This may fail if |
| 632 | // mutator updates before us, but it's OK. This is achived |
| 633 | // using a strong compare-and-set (CAS) operation with relaxed |
| 634 | // memory synchronization ordering, where the expected value is |
| 635 | // the old reference and the desired value is the new reference. |
| 636 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 637 | // instruction, which requires the expected value (the old |
| 638 | // reference) to be in EAX. Save RAX beforehand, and move the |
| 639 | // expected value (stored in `temp1_`) into EAX. |
| 640 | __ movq(temp2_, CpuRegister(RAX)); |
| 641 | __ movl(CpuRegister(RAX), temp1_); |
| 642 | |
| 643 | // Convenience aliases. |
| 644 | CpuRegister base = obj_; |
| 645 | CpuRegister expected = CpuRegister(RAX); |
| 646 | CpuRegister value = ref_cpu_reg; |
| 647 | |
| 648 | bool base_equals_value = (base.AsRegister() == value.AsRegister()); |
| 649 | Register value_reg = ref_reg; |
| 650 | if (kPoisonHeapReferences) { |
| 651 | if (base_equals_value) { |
| 652 | // If `base` and `value` are the same register location, move |
| 653 | // `value_reg` to a temporary register. This way, poisoning |
| 654 | // `value_reg` won't invalidate `base`. |
| 655 | value_reg = temp1_.AsRegister(); |
| 656 | __ movl(CpuRegister(value_reg), base); |
| 657 | } |
| 658 | |
| 659 | // Check that the register allocator did not assign the location |
| 660 | // of `expected` (RAX) to `value` nor to `base`, so that heap |
| 661 | // poisoning (when enabled) works as intended below. |
| 662 | // - If `value` were equal to `expected`, both references would |
| 663 | // be poisoned twice, meaning they would not be poisoned at |
| 664 | // all, as heap poisoning uses address negation. |
| 665 | // - If `base` were equal to `expected`, poisoning `expected` |
| 666 | // would invalidate `base`. |
| 667 | DCHECK_NE(value_reg, expected.AsRegister()); |
| 668 | DCHECK_NE(base.AsRegister(), expected.AsRegister()); |
| 669 | |
| 670 | __ PoisonHeapReference(expected); |
| 671 | __ PoisonHeapReference(CpuRegister(value_reg)); |
| 672 | } |
| 673 | |
| 674 | __ LockCmpxchgl(field_addr_, CpuRegister(value_reg)); |
| 675 | |
| 676 | // If heap poisoning is enabled, we need to unpoison the values |
| 677 | // that were poisoned earlier. |
| 678 | if (kPoisonHeapReferences) { |
| 679 | if (base_equals_value) { |
| 680 | // `value_reg` has been moved to a temporary register, no need |
| 681 | // to unpoison it. |
| 682 | } else { |
| 683 | __ UnpoisonHeapReference(CpuRegister(value_reg)); |
| 684 | } |
| 685 | // No need to unpoison `expected` (RAX), as it is be overwritten below. |
| 686 | } |
| 687 | |
| 688 | // Restore RAX. |
| 689 | __ movq(CpuRegister(RAX), temp2_); |
| 690 | |
| 691 | __ Bind(&done); |
| 692 | __ jmp(GetExitLabel()); |
| 693 | } |
| 694 | |
| 695 | private: |
| 696 | // The location (register) of the marked object reference. |
| 697 | const Location ref_; |
| 698 | // The register containing the object holding the marked object reference field. |
| 699 | const CpuRegister obj_; |
| 700 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 701 | const Address field_addr_; |
| 702 | |
| 703 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 704 | const bool unpoison_ref_before_marking_; |
| 705 | |
| 706 | const CpuRegister temp1_; |
| 707 | const CpuRegister temp2_; |
| 708 | |
| 709 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86_64); |
| 710 | }; |
| 711 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 712 | // Slow path generating a read barrier for a heap reference. |
| 713 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 714 | public: |
| 715 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 716 | Location out, |
| 717 | Location ref, |
| 718 | Location obj, |
| 719 | uint32_t offset, |
| 720 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 721 | : SlowPathCode(instruction), |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 722 | out_(out), |
| 723 | ref_(ref), |
| 724 | obj_(obj), |
| 725 | offset_(offset), |
| 726 | index_(index) { |
| 727 | DCHECK(kEmitCompilerReadBarrier); |
| 728 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 729 | // object has been overwritten by (or after) the heap object |
| 730 | // reference load to be instrumented, e.g.: |
| 731 | // |
| 732 | // __ movl(out, Address(out, offset)); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 733 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 734 | // |
| 735 | // In that case, we have lost the information about the original |
| 736 | // object, and the emitted read barrier cannot work properly. |
| 737 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 738 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 739 | } |
| 740 | |
| 741 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 742 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 743 | LocationSummary* locations = instruction_->GetLocations(); |
| 744 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 745 | DCHECK(locations->CanCall()); |
| 746 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 747 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 748 | instruction_->IsStaticFieldGet() || |
| 749 | instruction_->IsArrayGet() || |
| 750 | instruction_->IsInstanceOf() || |
| 751 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 752 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 753 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 754 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 755 | |
| 756 | __ Bind(GetEntryLabel()); |
| 757 | SaveLiveRegisters(codegen, locations); |
| 758 | |
| 759 | // We may have to change the index's value, but as `index_` is a |
| 760 | // constant member (like other "inputs" of this slow path), |
| 761 | // introduce a copy of it, `index`. |
| 762 | Location index = index_; |
| 763 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 764 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 765 | if (instruction_->IsArrayGet()) { |
| 766 | // Compute real offset and store it in index_. |
| 767 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 768 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 769 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 770 | // We are about to change the value of `index_reg` (see the |
| 771 | // calls to art::x86_64::X86_64Assembler::shll and |
| 772 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 773 | // has not been saved by the previous call to |
| 774 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 775 | // callee-save register -- |
| 776 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 777 | // callee-save registers, as it has been designed with the |
| 778 | // assumption that callee-save registers are supposed to be |
| 779 | // handled by the called function. So, as a callee-save |
| 780 | // register, `index_reg` _would_ eventually be saved onto |
| 781 | // the stack, but it would be too late: we would have |
| 782 | // changed its value earlier. Therefore, we manually save |
| 783 | // it here into another freely available register, |
| 784 | // `free_reg`, chosen of course among the caller-save |
| 785 | // registers (as a callee-save `free_reg` register would |
| 786 | // exhibit the same problem). |
| 787 | // |
| 788 | // Note we could have requested a temporary register from |
| 789 | // the register allocator instead; but we prefer not to, as |
| 790 | // this is a slow path, and we know we can find a |
| 791 | // caller-save register that is available. |
| 792 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 793 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 794 | index_reg = free_reg; |
| 795 | index = Location::RegisterLocation(index_reg); |
| 796 | } else { |
| 797 | // The initial register stored in `index_` has already been |
| 798 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 799 | // (as it is not a callee-save register), so we can freely |
| 800 | // use it. |
| 801 | } |
| 802 | // Shifting the index value contained in `index_reg` by the |
| 803 | // scale factor (2) cannot overflow in practice, as the |
| 804 | // runtime is unable to allocate object arrays with a size |
| 805 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 806 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 807 | static_assert( |
| 808 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 809 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 810 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 811 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 812 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 813 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 814 | // (as in the case of ArrayGet), as it is actually an offset |
| 815 | // to an object field within an object. |
| 816 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 817 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 818 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 819 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 820 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 821 | DCHECK_EQ(offset_, 0U); |
| 822 | DCHECK(index_.IsRegister()); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | // We're moving two or three locations to locations that could |
| 827 | // overlap, so we need a parallel move resolver. |
| 828 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 829 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 830 | parallel_move.AddMove(ref_, |
| 831 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 832 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 833 | nullptr); |
| 834 | parallel_move.AddMove(obj_, |
| 835 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 836 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 837 | nullptr); |
| 838 | if (index.IsValid()) { |
| 839 | parallel_move.AddMove(index, |
| 840 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 841 | DataType::Type::kInt32, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 842 | nullptr); |
| 843 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 844 | } else { |
| 845 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 846 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 847 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 848 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 849 | instruction_, |
| 850 | instruction_->GetDexPc(), |
| 851 | this); |
| 852 | CheckEntrypointTypes< |
| 853 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 854 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 855 | |
| 856 | RestoreLiveRegisters(codegen, locations); |
| 857 | __ jmp(GetExitLabel()); |
| 858 | } |
| 859 | |
| 860 | const char* GetDescription() const OVERRIDE { |
| 861 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 862 | } |
| 863 | |
| 864 | private: |
| 865 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 866 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 867 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 868 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 869 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 870 | return static_cast<CpuRegister>(i); |
| 871 | } |
| 872 | } |
| 873 | // We shall never fail to find a free caller-save register, as |
| 874 | // there are more than two core caller-save registers on x86-64 |
| 875 | // (meaning it is possible to find one which is different from |
| 876 | // `ref` and `obj`). |
| 877 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 878 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 879 | UNREACHABLE(); |
| 880 | } |
| 881 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 882 | const Location out_; |
| 883 | const Location ref_; |
| 884 | const Location obj_; |
| 885 | const uint32_t offset_; |
| 886 | // An additional location containing an index to an array. |
| 887 | // Only used for HArrayGet and the UnsafeGetObject & |
| 888 | // UnsafeGetObjectVolatile intrinsics. |
| 889 | const Location index_; |
| 890 | |
| 891 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 892 | }; |
| 893 | |
| 894 | // Slow path generating a read barrier for a GC root. |
| 895 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 896 | public: |
| 897 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 898 | : SlowPathCode(instruction), out_(out), root_(root) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 899 | DCHECK(kEmitCompilerReadBarrier); |
| 900 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 901 | |
| 902 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 903 | LocationSummary* locations = instruction_->GetLocations(); |
| 904 | DCHECK(locations->CanCall()); |
| 905 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 906 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 907 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 908 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 909 | |
| 910 | __ Bind(GetEntryLabel()); |
| 911 | SaveLiveRegisters(codegen, locations); |
| 912 | |
| 913 | InvokeRuntimeCallingConvention calling_convention; |
| 914 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 915 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 916 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 917 | instruction_, |
| 918 | instruction_->GetDexPc(), |
| 919 | this); |
| 920 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 921 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 922 | |
| 923 | RestoreLiveRegisters(codegen, locations); |
| 924 | __ jmp(GetExitLabel()); |
| 925 | } |
| 926 | |
| 927 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 928 | |
| 929 | private: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 930 | const Location out_; |
| 931 | const Location root_; |
| 932 | |
| 933 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 934 | }; |
| 935 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 936 | #undef __ |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 937 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 938 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 939 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 940 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 941 | switch (cond) { |
| 942 | case kCondEQ: return kEqual; |
| 943 | case kCondNE: return kNotEqual; |
| 944 | case kCondLT: return kLess; |
| 945 | case kCondLE: return kLessEqual; |
| 946 | case kCondGT: return kGreater; |
| 947 | case kCondGE: return kGreaterEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 948 | case kCondB: return kBelow; |
| 949 | case kCondBE: return kBelowEqual; |
| 950 | case kCondA: return kAbove; |
| 951 | case kCondAE: return kAboveEqual; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 952 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 953 | LOG(FATAL) << "Unreachable"; |
| 954 | UNREACHABLE(); |
| 955 | } |
| 956 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 957 | // Maps FP condition to x86_64 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 958 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 959 | switch (cond) { |
| 960 | case kCondEQ: return kEqual; |
| 961 | case kCondNE: return kNotEqual; |
| 962 | case kCondLT: return kBelow; |
| 963 | case kCondLE: return kBelowEqual; |
| 964 | case kCondGT: return kAbove; |
| 965 | case kCondGE: return kAboveEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 966 | default: break; // should not happen |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 967 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 968 | LOG(FATAL) << "Unreachable"; |
| 969 | UNREACHABLE(); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 970 | } |
| 971 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 972 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 973 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 974 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 975 | return desired_dispatch_info; |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 976 | } |
| 977 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 978 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall( |
| 979 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 980 | // All registers are assumed to be correctly set up. |
| Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 981 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 982 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 983 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 984 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 985 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 986 | uint32_t offset = |
| 987 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 988 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip */ true)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 989 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 990 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 991 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 992 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 993 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 994 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: |
| 995 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 996 | __ leal(temp.AsRegister<CpuRegister>(), |
| 997 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 998 | RecordBootImageMethodPatch(invoke); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 999 | break; |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1000 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 1001 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 1002 | __ movl(temp.AsRegister<CpuRegister>(), |
| 1003 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1004 | RecordBootImageRelRoPatch(GetBootImageOffset(invoke)); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1005 | break; |
| 1006 | } |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1007 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1008 | __ movq(temp.AsRegister<CpuRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 1009 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1010 | RecordMethodBssEntryPatch(invoke); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1011 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1012 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 1013 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 1014 | Load64BitValue(temp.AsRegister<CpuRegister>(), invoke->GetMethodAddress()); |
| 1015 | break; |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1016 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 1017 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 1018 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1019 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | switch (invoke->GetCodePtrLocation()) { |
| 1023 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 1024 | __ call(&frame_entry_label_); |
| 1025 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1026 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 1027 | // (callee_method + offset_of_quick_compiled_code)() |
| 1028 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1029 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1030 | kX86_64PointerSize).SizeValue())); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1031 | break; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1032 | } |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1033 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1034 | |
| 1035 | DCHECK(!IsLeafMethod()); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1036 | } |
| 1037 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1038 | void CodeGeneratorX86_64::GenerateVirtualCall( |
| 1039 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1040 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1041 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1042 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1043 | |
| 1044 | // Use the calling convention instead of the location of the receiver, as |
| 1045 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1046 | // slow path, the arguments have been moved to the right place, so here we are |
| 1047 | // guaranteed that the receiver is the first register of the calling convention. |
| 1048 | InvokeDexCallingConvention calling_convention; |
| 1049 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1050 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1051 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1052 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1053 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1054 | MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1055 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1056 | // emit a read barrier for the previous class reference load. |
| 1057 | // However this is not required in practice, as this is an |
| 1058 | // intermediate/temporary reference and because the current |
| 1059 | // concurrent copying collector keeps the from-space memory |
| 1060 | // intact/accessible until the end of the marking phase (the |
| 1061 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1062 | __ MaybeUnpoisonHeapReference(temp); |
| 1063 | // temp = temp->GetMethodAt(method_offset); |
| 1064 | __ movq(temp, Address(temp, method_offset)); |
| 1065 | // call temp->GetEntryPoint(); |
| 1066 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1067 | kX86_64PointerSize).SizeValue())); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1068 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1071 | void CodeGeneratorX86_64::RecordBootImageIntrinsicPatch(uint32_t intrinsic_data) { |
| 1072 | boot_image_intrinsic_patches_.emplace_back(/* target_dex_file */ nullptr, intrinsic_data); |
| 1073 | __ Bind(&boot_image_intrinsic_patches_.back().label); |
| 1074 | } |
| 1075 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1076 | void CodeGeneratorX86_64::RecordBootImageRelRoPatch(uint32_t boot_image_offset) { |
| 1077 | boot_image_method_patches_.emplace_back(/* target_dex_file */ nullptr, boot_image_offset); |
| 1078 | __ Bind(&boot_image_method_patches_.back().label); |
| 1079 | } |
| 1080 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1081 | void CodeGeneratorX86_64::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 1082 | boot_image_method_patches_.emplace_back( |
| 1083 | invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1084 | __ Bind(&boot_image_method_patches_.back().label); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1087 | void CodeGeneratorX86_64::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { |
| 1088 | method_bss_entry_patches_.emplace_back(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 1089 | __ Bind(&method_bss_entry_patches_.back().label); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1090 | } |
| 1091 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1092 | void CodeGeneratorX86_64::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 1093 | boot_image_type_patches_.emplace_back( |
| 1094 | &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1095 | __ Bind(&boot_image_type_patches_.back().label); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1096 | } |
| 1097 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1098 | Label* CodeGeneratorX86_64::NewTypeBssEntryPatch(HLoadClass* load_class) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1099 | type_bss_entry_patches_.emplace_back( |
| 1100 | &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1101 | return &type_bss_entry_patches_.back().label; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1104 | void CodeGeneratorX86_64::RecordBootImageStringPatch(HLoadString* load_string) { |
| 1105 | boot_image_string_patches_.emplace_back( |
| 1106 | &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 1107 | __ Bind(&boot_image_string_patches_.back().label); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1108 | } |
| 1109 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1110 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
| 1111 | DCHECK(!GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1112 | string_bss_entry_patches_.emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1113 | &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1114 | return &string_bss_entry_patches_.back().label; |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1117 | void CodeGeneratorX86_64::LoadBootImageAddress(CpuRegister reg, uint32_t boot_image_reference) { |
| 1118 | if (GetCompilerOptions().IsBootImage()) { |
| 1119 | __ leal(reg, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 1120 | RecordBootImageIntrinsicPatch(boot_image_reference); |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 1121 | } else if (Runtime::Current()->IsAotCompiler()) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1122 | __ movl(reg, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1123 | RecordBootImageRelRoPatch(boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1124 | } else { |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 1125 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1126 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1127 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1128 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1129 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 1130 | } |
| 1131 | } |
| 1132 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1133 | void CodeGeneratorX86_64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 1134 | uint32_t boot_image_offset) { |
| 1135 | DCHECK(invoke->IsStatic()); |
| 1136 | InvokeRuntimeCallingConvention calling_convention; |
| 1137 | CpuRegister argument = CpuRegister(calling_convention.GetRegisterAt(0)); |
| 1138 | if (GetCompilerOptions().IsBootImage()) { |
| 1139 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 1140 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 1141 | __ leal(argument, |
| 1142 | Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 1143 | MethodReference target_method = invoke->GetTargetMethod(); |
| 1144 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 1145 | boot_image_type_patches_.emplace_back(target_method.dex_file, type_idx.index_); |
| 1146 | __ Bind(&boot_image_type_patches_.back().label); |
| 1147 | } else { |
| 1148 | LoadBootImageAddress(argument, boot_image_offset); |
| 1149 | } |
| 1150 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 1151 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 1152 | } |
| 1153 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1154 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 1155 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 1156 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 1157 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1158 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1159 | inline void CodeGeneratorX86_64::EmitPcRelativeLinkerPatches( |
| 1160 | const ArenaDeque<PatchInfo<Label>>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1161 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1162 | for (const PatchInfo<Label>& info : infos) { |
| 1163 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1164 | linker_patches->push_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1165 | Factory(literal_offset, info.target_dex_file, info.label.Position(), info.offset_or_index)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1169 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 1170 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 1171 | const DexFile* target_dex_file, |
| 1172 | uint32_t pc_insn_offset, |
| 1173 | uint32_t boot_image_offset) { |
| 1174 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 1175 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1178 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1179 | DCHECK(linker_patches->empty()); |
| 1180 | size_t size = |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1181 | boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1182 | method_bss_entry_patches_.size() + |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1183 | boot_image_type_patches_.size() + |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1184 | type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1185 | boot_image_string_patches_.size() + |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1186 | string_bss_entry_patches_.size() + |
| 1187 | boot_image_intrinsic_patches_.size(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1188 | linker_patches->reserve(size); |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1189 | if (GetCompilerOptions().IsBootImage()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1190 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1191 | boot_image_method_patches_, linker_patches); |
| 1192 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1193 | boot_image_type_patches_, linker_patches); |
| 1194 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1195 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1196 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 1197 | boot_image_intrinsic_patches_, linker_patches); |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1198 | } else { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1199 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1200 | boot_image_method_patches_, linker_patches); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1201 | DCHECK(boot_image_type_patches_.empty()); |
| 1202 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1203 | DCHECK(boot_image_intrinsic_patches_.empty()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1204 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1205 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1206 | method_bss_entry_patches_, linker_patches); |
| 1207 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1208 | type_bss_entry_patches_, linker_patches); |
| 1209 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1210 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1211 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1214 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1215 | stream << Register(reg); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1219 | stream << FloatRegister(reg); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1220 | } |
| 1221 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1222 | const X86_64InstructionSetFeatures& CodeGeneratorX86_64::GetInstructionSetFeatures() const { |
| 1223 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86_64InstructionSetFeatures(); |
| 1224 | } |
| 1225 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1226 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1227 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1228 | return kX86_64WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1229 | } |
| 1230 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1231 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1232 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1233 | return kX86_64WordSize; |
| 1234 | } |
| 1235 | |
| 1236 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1237 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1238 | __ movups(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1239 | } else { |
| 1240 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1241 | } |
| 1242 | return GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1246 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1247 | __ movups(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1248 | } else { |
| 1249 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1250 | } |
| 1251 | return GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1252 | } |
| 1253 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1254 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1255 | HInstruction* instruction, |
| 1256 | uint32_t dex_pc, |
| 1257 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1258 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1259 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1260 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1261 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1262 | } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1263 | } |
| 1264 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1265 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1266 | HInstruction* instruction, |
| 1267 | SlowPathCode* slow_path) { |
| 1268 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1269 | GenerateInvokeRuntime(entry_point_offset); |
| 1270 | } |
| 1271 | |
| 1272 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1273 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
| 1274 | } |
| 1275 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1276 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1277 | // Use a fake return address register to mimic Quick. |
| 1278 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1279 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1280 | const CompilerOptions& compiler_options, |
| 1281 | OptimizingCompilerStats* stats) |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1282 | : CodeGenerator(graph, |
| 1283 | kNumberOfCpuRegisters, |
| 1284 | kNumberOfFloatRegisters, |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1285 | kNumberOfCpuRegisterPairs, |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1286 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1287 | arraysize(kCoreCalleeSaves)) |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1288 | | (1 << kFakeReturnRegister), |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1289 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1290 | arraysize(kFpuCalleeSaves)), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1291 | compiler_options, |
| 1292 | stats), |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1293 | block_labels_(nullptr), |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1294 | location_builder_(graph, this), |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1295 | instruction_visitor_(graph, this), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1296 | move_resolver_(graph->GetAllocator(), this), |
| 1297 | assembler_(graph->GetAllocator()), |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1298 | constant_area_start_(0), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1299 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1300 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1301 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1302 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1303 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1304 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1305 | boot_image_intrinsic_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1306 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1307 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1308 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1309 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1310 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1311 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1312 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1313 | CodeGeneratorX86_64* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1314 | : InstructionCodeGenerator(graph, codegen), |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1315 | assembler_(codegen->GetAssembler()), |
| 1316 | codegen_(codegen) {} |
| 1317 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1318 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1319 | // Stack register is always reserved. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1320 | blocked_core_registers_[RSP] = true; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1321 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1322 | // Block the register used as TMP. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1323 | blocked_core_registers_[TMP] = true; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1324 | } |
| 1325 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1326 | static dwarf::Reg DWARFReg(Register reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1327 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1328 | } |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1329 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1330 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1331 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1332 | } |
| 1333 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1334 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1335 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1336 | __ Bind(&frame_entry_label_); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1337 | bool skip_overflow_check = IsLeafMethod() |
| Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1338 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1339 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1340 | |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1341 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1342 | __ addw(Address(CpuRegister(kMethodRegisterArgument), |
| 1343 | ArtMethod::HotnessCountOffset().Int32Value()), |
| 1344 | Immediate(1)); |
| 1345 | } |
| 1346 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1347 | if (!skip_overflow_check) { |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1348 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86_64); |
| 1349 | __ testq(CpuRegister(RAX), Address(CpuRegister(RSP), -static_cast<int32_t>(reserved_bytes))); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1350 | RecordPcInfo(nullptr, 0); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1351 | } |
| Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1352 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1353 | if (HasEmptyFrame()) { |
| 1354 | return; |
| 1355 | } |
| 1356 | |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1357 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1358 | Register reg = kCoreCalleeSaves[i]; |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1359 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1360 | __ pushq(CpuRegister(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1361 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1362 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1363 | } |
| 1364 | } |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1365 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1366 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1367 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1368 | __ cfi().AdjustCFAOffset(adjust); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1369 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1370 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1371 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1372 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1373 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1374 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1375 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1376 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1377 | } |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1378 | } |
| 1379 | |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1380 | // Save the current method if we need it. Note that we do not |
| 1381 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1382 | // in the SSA graph. |
| 1383 | if (RequiresCurrentMethod()) { |
| 1384 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1385 | CpuRegister(kMethodRegisterArgument)); |
| 1386 | } |
| Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1387 | |
| 1388 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1389 | // Initialize should_deoptimize flag to 0. |
| 1390 | __ movl(Address(CpuRegister(RSP), GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1391 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | void CodeGeneratorX86_64::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1395 | __ cfi().RememberState(); |
| 1396 | if (!HasEmptyFrame()) { |
| 1397 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1398 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1399 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1400 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1401 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1402 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1403 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1408 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1409 | __ cfi().AdjustCFAOffset(-adjust); |
| 1410 | |
| 1411 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1412 | Register reg = kCoreCalleeSaves[i]; |
| 1413 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1414 | __ popq(CpuRegister(reg)); |
| 1415 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1416 | __ cfi().Restore(DWARFReg(reg)); |
| 1417 | } |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1418 | } |
| 1419 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1420 | __ ret(); |
| 1421 | __ cfi().RestoreState(); |
| 1422 | __ cfi().DefCFAOffset(GetFrameSize()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1423 | } |
| 1424 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1425 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1426 | __ Bind(GetLabelOf(block)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1427 | } |
| 1428 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1429 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1430 | if (source.Equals(destination)) { |
| 1431 | return; |
| 1432 | } |
| 1433 | if (destination.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1434 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1435 | if (source.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1436 | __ movq(dest, source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1437 | } else if (source.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1438 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1439 | } else if (source.IsStackSlot()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1440 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1441 | } else if (source.IsConstant()) { |
| 1442 | HConstant* constant = source.GetConstant(); |
| 1443 | if (constant->IsLongConstant()) { |
| 1444 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1445 | } else { |
| 1446 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1447 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1448 | } else { |
| 1449 | DCHECK(source.IsDoubleStackSlot()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1450 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1451 | } |
| 1452 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1453 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1454 | if (source.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1455 | __ movd(dest, source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1456 | } else if (source.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1457 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1458 | } else if (source.IsConstant()) { |
| 1459 | HConstant* constant = source.GetConstant(); |
| 1460 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1461 | if (constant->IsFloatConstant()) { |
| 1462 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1463 | } else { |
| 1464 | Load64BitValue(dest, value); |
| 1465 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1466 | } else if (source.IsStackSlot()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1467 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1468 | } else { |
| 1469 | DCHECK(source.IsDoubleStackSlot()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1470 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1471 | } |
| 1472 | } else if (destination.IsStackSlot()) { |
| 1473 | if (source.IsRegister()) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1474 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1475 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1476 | } else if (source.IsFpuRegister()) { |
| 1477 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1478 | source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1479 | } else if (source.IsConstant()) { |
| 1480 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1481 | int32_t value = GetInt32ValueOf(constant); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1482 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1483 | } else { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1484 | DCHECK(source.IsStackSlot()) << source; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1485 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1486 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1487 | } |
| 1488 | } else { |
| 1489 | DCHECK(destination.IsDoubleStackSlot()); |
| 1490 | if (source.IsRegister()) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1491 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1492 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1493 | } else if (source.IsFpuRegister()) { |
| 1494 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1495 | source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1496 | } else if (source.IsConstant()) { |
| 1497 | HConstant* constant = source.GetConstant(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1498 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1499 | int64_t value = GetInt64ValueOf(constant); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1500 | Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1501 | } else { |
| 1502 | DCHECK(source.IsDoubleStackSlot()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1503 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1504 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1505 | } |
| 1506 | } |
| 1507 | } |
| 1508 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1509 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1510 | DCHECK(location.IsRegister()); |
| 1511 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1512 | } |
| 1513 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1514 | void CodeGeneratorX86_64::MoveLocation( |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1515 | Location dst, Location src, DataType::Type dst_type ATTRIBUTE_UNUSED) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1516 | Move(dst, src); |
| 1517 | } |
| 1518 | |
| 1519 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1520 | if (location.IsRegister()) { |
| 1521 | locations->AddTemp(location); |
| 1522 | } else { |
| 1523 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1524 | } |
| 1525 | } |
| 1526 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1527 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1528 | if (successor->IsExitBlock()) { |
| 1529 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1530 | return; // no code needed |
| 1531 | } |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1532 | |
| 1533 | HBasicBlock* block = got->GetBlock(); |
| 1534 | HInstruction* previous = got->GetPrevious(); |
| 1535 | |
| 1536 | HLoopInformation* info = block->GetLoopInformation(); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1537 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1538 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1539 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), 0)); |
| 1540 | __ addw(Address(CpuRegister(TMP), ArtMethod::HotnessCountOffset().Int32Value()), |
| 1541 | Immediate(1)); |
| 1542 | } |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1543 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1544 | return; |
| 1545 | } |
| 1546 | |
| 1547 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1548 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1549 | } |
| 1550 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1551 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1552 | } |
| 1553 | } |
| 1554 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1555 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1556 | got->SetLocations(nullptr); |
| 1557 | } |
| 1558 | |
| 1559 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1560 | HandleGoto(got, got->GetSuccessor()); |
| 1561 | } |
| 1562 | |
| 1563 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1564 | try_boundary->SetLocations(nullptr); |
| 1565 | } |
| 1566 | |
| 1567 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1568 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1569 | if (!successor->IsExitBlock()) { |
| 1570 | HandleGoto(try_boundary, successor); |
| 1571 | } |
| 1572 | } |
| 1573 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1574 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1575 | exit->SetLocations(nullptr); |
| 1576 | } |
| 1577 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1578 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1579 | } |
| 1580 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1581 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1582 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1583 | LabelType* true_label, |
| 1584 | LabelType* false_label) { |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1585 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1586 | __ j(kUnordered, true_label); |
| 1587 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1588 | __ j(kUnordered, false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1589 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1590 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1591 | } |
| 1592 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1593 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1594 | LocationSummary* locations = condition->GetLocations(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1595 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1596 | Location left = locations->InAt(0); |
| 1597 | Location right = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1598 | DataType::Type type = condition->InputAt(0)->GetType(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1599 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1600 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1601 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1602 | case DataType::Type::kInt8: |
| 1603 | case DataType::Type::kUint16: |
| 1604 | case DataType::Type::kInt16: |
| 1605 | case DataType::Type::kInt32: |
| 1606 | case DataType::Type::kReference: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1607 | codegen_->GenerateIntCompare(left, right); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1608 | break; |
| 1609 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1610 | case DataType::Type::kInt64: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1611 | codegen_->GenerateLongCompare(left, right); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1612 | break; |
| 1613 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1614 | case DataType::Type::kFloat32: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1615 | if (right.IsFpuRegister()) { |
| 1616 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1617 | } else if (right.IsConstant()) { |
| 1618 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1619 | codegen_->LiteralFloatAddress( |
| 1620 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1621 | } else { |
| 1622 | DCHECK(right.IsStackSlot()); |
| 1623 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1624 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1625 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1626 | break; |
| 1627 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1628 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1629 | if (right.IsFpuRegister()) { |
| 1630 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1631 | } else if (right.IsConstant()) { |
| 1632 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1633 | codegen_->LiteralDoubleAddress( |
| 1634 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1635 | } else { |
| 1636 | DCHECK(right.IsDoubleStackSlot()); |
| 1637 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1638 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1639 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1640 | break; |
| 1641 | } |
| 1642 | default: |
| 1643 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | template<class LabelType> |
| 1648 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1649 | LabelType* true_target_in, |
| 1650 | LabelType* false_target_in) { |
| 1651 | // Generated branching requires both targets to be explicit. If either of the |
| 1652 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1653 | LabelType fallthrough_target; |
| 1654 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1655 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1656 | |
| 1657 | // Generate the comparison to set the CC. |
| 1658 | GenerateCompareTest(condition); |
| 1659 | |
| 1660 | // Now generate the correct jump(s). |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1661 | DataType::Type type = condition->InputAt(0)->GetType(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1662 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1663 | case DataType::Type::kInt64: { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1664 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1665 | break; |
| 1666 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1667 | case DataType::Type::kFloat32: { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1668 | GenerateFPJumps(condition, true_target, false_target); |
| 1669 | break; |
| 1670 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1671 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1672 | GenerateFPJumps(condition, true_target, false_target); |
| 1673 | break; |
| 1674 | } |
| 1675 | default: |
| 1676 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1677 | } |
| 1678 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1679 | if (false_target != &fallthrough_target) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1680 | __ jmp(false_target); |
| 1681 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1682 | |
| 1683 | if (fallthrough_target.IsLinked()) { |
| 1684 | __ Bind(&fallthrough_target); |
| 1685 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1686 | } |
| 1687 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1688 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1689 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1690 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1691 | // conditions if they are materialized due to the complex branching. |
| 1692 | return cond->IsCondition() && |
| 1693 | cond->GetNext() == branch && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1694 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1695 | } |
| 1696 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1697 | template<class LabelType> |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1698 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1699 | size_t condition_input_index, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1700 | LabelType* true_target, |
| 1701 | LabelType* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1702 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1703 | |
| 1704 | if (true_target == nullptr && false_target == nullptr) { |
| 1705 | // Nothing to do. The code always falls through. |
| 1706 | return; |
| 1707 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1708 | // Constant condition, statically compared against "true" (integer value 1). |
| 1709 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1710 | if (true_target != nullptr) { |
| 1711 | __ jmp(true_target); |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1712 | } |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1713 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1714 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1715 | if (false_target != nullptr) { |
| 1716 | __ jmp(false_target); |
| 1717 | } |
| 1718 | } |
| 1719 | return; |
| 1720 | } |
| 1721 | |
| 1722 | // The following code generates these patterns: |
| 1723 | // (1) true_target == nullptr && false_target != nullptr |
| 1724 | // - opposite condition true => branch to false_target |
| 1725 | // (2) true_target != nullptr && false_target == nullptr |
| 1726 | // - condition true => branch to true_target |
| 1727 | // (3) true_target != nullptr && false_target != nullptr |
| 1728 | // - condition true => branch to true_target |
| 1729 | // - branch to false_target |
| 1730 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1731 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1732 | if (true_target == nullptr) { |
| 1733 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1734 | } else { |
| 1735 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1736 | } |
| 1737 | } else { |
| 1738 | // Materialized condition, compare against 0. |
| 1739 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1740 | if (lhs.IsRegister()) { |
| 1741 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1742 | } else { |
| 1743 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1744 | } |
| 1745 | if (true_target == nullptr) { |
| 1746 | __ j(kEqual, false_target); |
| 1747 | } else { |
| 1748 | __ j(kNotEqual, true_target); |
| 1749 | } |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1750 | } |
| 1751 | } else { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1752 | // Condition has not been materialized, use its inputs as the |
| 1753 | // comparison and its condition as the branch condition. |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1754 | HCondition* condition = cond->AsCondition(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1755 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1756 | // If this is a long or FP comparison that has been folded into |
| 1757 | // the HCondition, generate the comparison directly. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1758 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1759 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1760 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1761 | return; |
| 1762 | } |
| 1763 | |
| 1764 | Location lhs = condition->GetLocations()->InAt(0); |
| 1765 | Location rhs = condition->GetLocations()->InAt(1); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1766 | codegen_->GenerateIntCompare(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1767 | if (true_target == nullptr) { |
| 1768 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1769 | } else { |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1770 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1771 | } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1772 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1773 | |
| 1774 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1775 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1776 | if (true_target != nullptr && false_target != nullptr) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1777 | __ jmp(false_target); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1778 | } |
| 1779 | } |
| 1780 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1781 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1782 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1783 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1784 | locations->SetInAt(0, Location::Any()); |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1789 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1790 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1791 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1792 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1793 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1794 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1795 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1799 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1800 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1801 | InvokeRuntimeCallingConvention calling_convention; |
| 1802 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1803 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1804 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1805 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1806 | locations->SetInAt(0, Location::Any()); |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1811 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1812 | GenerateTestAndBranch<Label>(deoptimize, |
| 1813 | /* condition_input_index */ 0, |
| 1814 | slow_path->GetEntryLabel(), |
| 1815 | /* false_target */ nullptr); |
| 1816 | } |
| 1817 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1818 | void LocationsBuilderX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1819 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1820 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1821 | locations->SetOut(Location::RequiresRegister()); |
| 1822 | } |
| 1823 | |
| 1824 | void InstructionCodeGeneratorX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1825 | __ movl(flag->GetLocations()->Out().AsRegister<CpuRegister>(), |
| 1826 | Address(CpuRegister(RSP), codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1827 | } |
| 1828 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1829 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1830 | // There are no conditional move instructions for XMMs. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1831 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1832 | return false; |
| 1833 | } |
| 1834 | |
| 1835 | // A FP condition doesn't generate the single CC that we need. |
| 1836 | HInstruction* condition = select->GetCondition(); |
| 1837 | if (condition->IsCondition() && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1838 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1839 | return false; |
| 1840 | } |
| 1841 | |
| 1842 | // We can generate a CMOV for this Select. |
| 1843 | return true; |
| 1844 | } |
| 1845 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1846 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1847 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1848 | if (DataType::IsFloatingPointType(select->GetType())) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1849 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1850 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1851 | } else { |
| 1852 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1853 | if (SelectCanUseCMOV(select)) { |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1854 | if (select->InputAt(1)->IsConstant()) { |
| 1855 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1856 | } else { |
| 1857 | locations->SetInAt(1, Location::Any()); |
| 1858 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1859 | } else { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1860 | locations->SetInAt(1, Location::Any()); |
| 1861 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1862 | } |
| 1863 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1864 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1865 | } |
| 1866 | locations->SetOut(Location::SameAsFirstInput()); |
| 1867 | } |
| 1868 | |
| 1869 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1870 | LocationSummary* locations = select->GetLocations(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1871 | if (SelectCanUseCMOV(select)) { |
| 1872 | // If both the condition and the source types are integer, we can generate |
| 1873 | // a CMOV to implement Select. |
| 1874 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1875 | Location value_true_loc = locations->InAt(1); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1876 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1877 | |
| 1878 | HInstruction* select_condition = select->GetCondition(); |
| 1879 | Condition cond = kNotEqual; |
| 1880 | |
| 1881 | // Figure out how to test the 'condition'. |
| 1882 | if (select_condition->IsCondition()) { |
| 1883 | HCondition* condition = select_condition->AsCondition(); |
| 1884 | if (!condition->IsEmittedAtUseSite()) { |
| 1885 | // This was a previously materialized condition. |
| 1886 | // Can we use the existing condition code? |
| 1887 | if (AreEflagsSetFrom(condition, select)) { |
| 1888 | // Materialization was the previous instruction. Condition codes are right. |
| 1889 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1890 | } else { |
| 1891 | // No, we have to recreate the condition code. |
| 1892 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1893 | __ testl(cond_reg, cond_reg); |
| 1894 | } |
| 1895 | } else { |
| 1896 | GenerateCompareTest(condition); |
| 1897 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1898 | } |
| 1899 | } else { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1900 | // Must be a Boolean condition, which needs to be compared to 0. |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1901 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1902 | __ testl(cond_reg, cond_reg); |
| 1903 | } |
| 1904 | |
| 1905 | // If the condition is true, overwrite the output, which already contains false. |
| 1906 | // Generate the correct sized CMOV. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1907 | bool is_64_bit = DataType::Is64BitType(select->GetType()); |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1908 | if (value_true_loc.IsRegister()) { |
| 1909 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1910 | } else { |
| 1911 | __ cmov(cond, |
| 1912 | value_false, |
| 1913 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1914 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1915 | } else { |
| 1916 | NearLabel false_target; |
| 1917 | GenerateTestAndBranch<NearLabel>(select, |
| 1918 | /* condition_input_index */ 2, |
| 1919 | /* true_target */ nullptr, |
| 1920 | &false_target); |
| 1921 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1922 | __ Bind(&false_target); |
| 1923 | } |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1924 | } |
| 1925 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1926 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1927 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1930 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1931 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | void CodeGeneratorX86_64::GenerateNop() { |
| 1935 | __ nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1938 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1939 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1940 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1941 | // Handle the long/FP comparisons made in instruction simplification. |
| 1942 | switch (cond->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1943 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1944 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1945 | locations->SetInAt(1, Location::Any()); |
| 1946 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1947 | case DataType::Type::kFloat32: |
| 1948 | case DataType::Type::kFloat64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1949 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1950 | locations->SetInAt(1, Location::Any()); |
| 1951 | break; |
| 1952 | default: |
| 1953 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1954 | locations->SetInAt(1, Location::Any()); |
| 1955 | break; |
| 1956 | } |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1957 | if (!cond->IsEmittedAtUseSite()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1958 | locations->SetOut(Location::RequiresRegister()); |
| 1959 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1960 | } |
| 1961 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1962 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1963 | if (cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1964 | return; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1965 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1966 | |
| 1967 | LocationSummary* locations = cond->GetLocations(); |
| 1968 | Location lhs = locations->InAt(0); |
| 1969 | Location rhs = locations->InAt(1); |
| 1970 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1971 | NearLabel true_label, false_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1972 | |
| 1973 | switch (cond->InputAt(0)->GetType()) { |
| 1974 | default: |
| 1975 | // Integer case. |
| 1976 | |
| 1977 | // Clear output register: setcc only sets the low byte. |
| 1978 | __ xorl(reg, reg); |
| 1979 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1980 | codegen_->GenerateIntCompare(lhs, rhs); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1981 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1982 | return; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1983 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1984 | // Clear output register: setcc only sets the low byte. |
| 1985 | __ xorl(reg, reg); |
| 1986 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1987 | codegen_->GenerateLongCompare(lhs, rhs); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1988 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1989 | return; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1990 | case DataType::Type::kFloat32: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1991 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1992 | if (rhs.IsConstant()) { |
| 1993 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1994 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1995 | } else if (rhs.IsStackSlot()) { |
| 1996 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1997 | } else { |
| 1998 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1999 | } |
| 2000 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2001 | break; |
| 2002 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2003 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2004 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 2005 | if (rhs.IsConstant()) { |
| 2006 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2007 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 2008 | } else if (rhs.IsDoubleStackSlot()) { |
| 2009 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 2010 | } else { |
| 2011 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 2012 | } |
| 2013 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2014 | break; |
| 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | // Convert the jumps into the result. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2019 | NearLabel done_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2020 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2021 | // False case: result = 0. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2022 | __ Bind(&false_label); |
| 2023 | __ xorl(reg, reg); |
| 2024 | __ jmp(&done_label); |
| 2025 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2026 | // True case: result = 1. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2027 | __ Bind(&true_label); |
| 2028 | __ movl(reg, Immediate(1)); |
| 2029 | __ Bind(&done_label); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2033 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2037 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2041 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2045 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2049 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2053 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2057 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2061 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2065 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2069 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2073 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2077 | HandleCondition(comp); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2078 | } |
| 2079 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2080 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2081 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2085 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2089 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2093 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2097 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2101 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2105 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2109 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2112 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2113 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2114 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2115 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2116 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2117 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2118 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2119 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2120 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2121 | case DataType::Type::kInt32: |
| 2122 | case DataType::Type::kInt64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2123 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2124 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2125 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2126 | break; |
| 2127 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2128 | case DataType::Type::kFloat32: |
| 2129 | case DataType::Type::kFloat64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2130 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2131 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2132 | locations->SetOut(Location::RequiresRegister()); |
| 2133 | break; |
| 2134 | } |
| 2135 | default: |
| 2136 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2137 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2141 | LocationSummary* locations = compare->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2142 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2143 | Location left = locations->InAt(0); |
| 2144 | Location right = locations->InAt(1); |
| 2145 | |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2146 | NearLabel less, greater, done; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2147 | DataType::Type type = compare->InputAt(0)->GetType(); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2148 | Condition less_cond = kLess; |
| 2149 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2150 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2151 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2152 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2153 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2154 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2155 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2156 | case DataType::Type::kInt32: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2157 | codegen_->GenerateIntCompare(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2158 | break; |
| 2159 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2160 | case DataType::Type::kInt64: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2161 | codegen_->GenerateLongCompare(left, right); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2162 | break; |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2163 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2164 | case DataType::Type::kFloat32: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2165 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2166 | if (right.IsConstant()) { |
| 2167 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2168 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2169 | } else if (right.IsStackSlot()) { |
| 2170 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2171 | } else { |
| 2172 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2173 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2174 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2175 | less_cond = kBelow; // ucomis{s,d} sets CF |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2176 | break; |
| 2177 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2178 | case DataType::Type::kFloat64: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2179 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2180 | if (right.IsConstant()) { |
| 2181 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2182 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2183 | } else if (right.IsDoubleStackSlot()) { |
| 2184 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2185 | } else { |
| 2186 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2187 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2188 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2189 | less_cond = kBelow; // ucomis{s,d} sets CF |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2190 | break; |
| 2191 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2192 | default: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2193 | LOG(FATAL) << "Unexpected compare type " << type; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2194 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2195 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2196 | __ movl(out, Immediate(0)); |
| Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2197 | __ j(kEqual, &done); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2198 | __ j(less_cond, &less); |
| Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2199 | |
| Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2200 | __ Bind(&greater); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2201 | __ movl(out, Immediate(1)); |
| 2202 | __ jmp(&done); |
| 2203 | |
| 2204 | __ Bind(&less); |
| 2205 | __ movl(out, Immediate(-1)); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2206 | |
| 2207 | __ Bind(&done); |
| 2208 | } |
| 2209 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2210 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2211 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2212 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2213 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2214 | } |
| 2215 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2216 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2217 | // Will be generated at use site. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2218 | } |
| 2219 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2220 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2221 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2222 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2223 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2224 | } |
| 2225 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2226 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2227 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2228 | } |
| 2229 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2230 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2231 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2232 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2233 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2234 | } |
| 2235 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2236 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2237 | // Will be generated at use site. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2238 | } |
| 2239 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2240 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2241 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2242 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2243 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2244 | } |
| 2245 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2246 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2247 | // Will be generated at use site. |
| 2248 | } |
| 2249 | |
| 2250 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2251 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2252 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2253 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2254 | } |
| 2255 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2256 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2257 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2258 | // Will be generated at use site. |
| 2259 | } |
| 2260 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2261 | void LocationsBuilderX86_64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2262 | constructor_fence->SetLocations(nullptr); |
| 2263 | } |
| 2264 | |
| 2265 | void InstructionCodeGeneratorX86_64::VisitConstructorFence( |
| 2266 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2267 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2268 | } |
| 2269 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2270 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2271 | memory_barrier->SetLocations(nullptr); |
| 2272 | } |
| 2273 | |
| 2274 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2275 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2276 | } |
| 2277 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2278 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2279 | ret->SetLocations(nullptr); |
| 2280 | } |
| 2281 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2282 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2283 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2287 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2288 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2289 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2290 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2291 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2292 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2293 | case DataType::Type::kInt8: |
| 2294 | case DataType::Type::kUint16: |
| 2295 | case DataType::Type::kInt16: |
| 2296 | case DataType::Type::kInt32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2297 | case DataType::Type::kInt64: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2298 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2299 | break; |
| 2300 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2301 | case DataType::Type::kFloat32: |
| 2302 | case DataType::Type::kFloat64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2303 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2304 | break; |
| 2305 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2306 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2307 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2308 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2312 | if (kIsDebugBuild) { |
| 2313 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2314 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2315 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2316 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2317 | case DataType::Type::kInt8: |
| 2318 | case DataType::Type::kUint16: |
| 2319 | case DataType::Type::kInt16: |
| 2320 | case DataType::Type::kInt32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2321 | case DataType::Type::kInt64: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2322 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2323 | break; |
| 2324 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2325 | case DataType::Type::kFloat32: |
| 2326 | case DataType::Type::kFloat64: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2327 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2328 | XMM0); |
| 2329 | break; |
| 2330 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2331 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2332 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2333 | } |
| 2334 | } |
| 2335 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2336 | } |
| 2337 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2338 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(DataType::Type type) const { |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2339 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2340 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2341 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2342 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2343 | case DataType::Type::kInt8: |
| 2344 | case DataType::Type::kUint16: |
| 2345 | case DataType::Type::kInt16: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2346 | case DataType::Type::kUint32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2347 | case DataType::Type::kInt32: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2348 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2349 | case DataType::Type::kInt64: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2350 | return Location::RegisterLocation(RAX); |
| 2351 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2352 | case DataType::Type::kVoid: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2353 | return Location::NoLocation(); |
| 2354 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2355 | case DataType::Type::kFloat64: |
| 2356 | case DataType::Type::kFloat32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2357 | return Location::FpuRegisterLocation(XMM0); |
| 2358 | } |
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2359 | |
| 2360 | UNREACHABLE(); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2364 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2365 | } |
| 2366 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2367 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(DataType::Type type) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2368 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2369 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2370 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2371 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2372 | case DataType::Type::kInt8: |
| 2373 | case DataType::Type::kUint16: |
| 2374 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2375 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2376 | uint32_t index = gp_index_++; |
| 2377 | stack_index_++; |
| 2378 | if (index < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2379 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2380 | } else { |
| 2381 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2382 | } |
| 2383 | } |
| 2384 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2385 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2386 | uint32_t index = gp_index_; |
| 2387 | stack_index_ += 2; |
| 2388 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2389 | gp_index_ += 1; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2390 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2391 | } else { |
| 2392 | gp_index_ += 2; |
| 2393 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2394 | } |
| 2395 | } |
| 2396 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2397 | case DataType::Type::kFloat32: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2398 | uint32_t index = float_index_++; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2399 | stack_index_++; |
| 2400 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2401 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2402 | } else { |
| 2403 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2404 | } |
| 2405 | } |
| 2406 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2407 | case DataType::Type::kFloat64: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2408 | uint32_t index = float_index_++; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2409 | stack_index_ += 2; |
| 2410 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2411 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2412 | } else { |
| 2413 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2414 | } |
| 2415 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2416 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2417 | case DataType::Type::kUint32: |
| 2418 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2419 | case DataType::Type::kVoid: |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2420 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2421 | break; |
| 2422 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2423 | return Location::NoLocation(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2424 | } |
| 2425 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2426 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2427 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2428 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2429 | // the method_idx. |
| 2430 | HandleInvoke(invoke); |
| 2431 | } |
| 2432 | |
| 2433 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2434 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2435 | } |
| 2436 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2437 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2438 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2439 | // art::PrepareForRegisterAllocation. |
| 2440 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2441 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2442 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2443 | if (intrinsic.TryDispatch(invoke)) { |
| 2444 | return; |
| 2445 | } |
| 2446 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2447 | HandleInvoke(invoke); |
| 2448 | } |
| 2449 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2450 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2451 | if (invoke->GetLocations()->Intrinsified()) { |
| 2452 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2453 | intrinsic.Dispatch(invoke); |
| 2454 | return true; |
| 2455 | } |
| 2456 | return false; |
| 2457 | } |
| 2458 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2459 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2460 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2461 | // art::PrepareForRegisterAllocation. |
| 2462 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2463 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2464 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2465 | return; |
| 2466 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2467 | |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2468 | LocationSummary* locations = invoke->GetLocations(); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2469 | codegen_->GenerateStaticOrDirectCall( |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2470 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2471 | } |
| 2472 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2473 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2474 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2475 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2476 | } |
| 2477 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2478 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2479 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2480 | if (intrinsic.TryDispatch(invoke)) { |
| 2481 | return; |
| 2482 | } |
| 2483 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2484 | HandleInvoke(invoke); |
| 2485 | } |
| 2486 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2487 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2488 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2489 | return; |
| 2490 | } |
| 2491 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2492 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2493 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2494 | } |
| 2495 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2496 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2497 | HandleInvoke(invoke); |
| 2498 | // Add the hidden argument. |
| 2499 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2500 | } |
| 2501 | |
| 2502 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2503 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2504 | LocationSummary* locations = invoke->GetLocations(); |
| 2505 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2506 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2507 | Location receiver = locations->InAt(0); |
| 2508 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2509 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2510 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2511 | // won't be modified thereafter, before the `call` instruction. |
| 2512 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2513 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2514 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2515 | if (receiver.IsStackSlot()) { |
| 2516 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2517 | // /* HeapReference<Class> */ temp = temp->klass_ |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2518 | __ movl(temp, Address(temp, class_offset)); |
| 2519 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2520 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2521 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2522 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2523 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2524 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2525 | // emit a read barrier for the previous class reference load. |
| 2526 | // However this is not required in practice, as this is an |
| 2527 | // intermediate/temporary reference and because the current |
| 2528 | // concurrent copying collector keeps the from-space memory |
| 2529 | // intact/accessible until the end of the marking phase (the |
| 2530 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2531 | __ MaybeUnpoisonHeapReference(temp); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2532 | // temp = temp->GetAddressOfIMT() |
| 2533 | __ movq(temp, |
| 2534 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2535 | // temp = temp->GetImtEntryAt(method_offset); |
| 2536 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2537 | invoke->GetImtIndex(), kX86_64PointerSize)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2538 | // temp = temp->GetImtEntryAt(method_offset); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2539 | __ movq(temp, Address(temp, method_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2540 | // call temp->GetEntryPoint(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2541 | __ call(Address( |
| 2542 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2543 | |
| 2544 | DCHECK(!codegen_->IsLeafMethod()); |
| 2545 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2546 | } |
| 2547 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2548 | void LocationsBuilderX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2549 | HandleInvoke(invoke); |
| 2550 | } |
| 2551 | |
| 2552 | void InstructionCodeGeneratorX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2553 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2554 | } |
| 2555 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2556 | void LocationsBuilderX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2557 | HandleInvoke(invoke); |
| 2558 | } |
| 2559 | |
| 2560 | void InstructionCodeGeneratorX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2561 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2562 | } |
| 2563 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2564 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2565 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2566 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2567 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2568 | case DataType::Type::kInt32: |
| 2569 | case DataType::Type::kInt64: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2570 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2571 | locations->SetOut(Location::SameAsFirstInput()); |
| 2572 | break; |
| 2573 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2574 | case DataType::Type::kFloat32: |
| 2575 | case DataType::Type::kFloat64: |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2576 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2577 | locations->SetOut(Location::SameAsFirstInput()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2578 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2579 | break; |
| 2580 | |
| 2581 | default: |
| 2582 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2587 | LocationSummary* locations = neg->GetLocations(); |
| 2588 | Location out = locations->Out(); |
| 2589 | Location in = locations->InAt(0); |
| 2590 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2591 | case DataType::Type::kInt32: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2592 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2593 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2594 | __ negl(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2595 | break; |
| 2596 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2597 | case DataType::Type::kInt64: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2598 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2599 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2600 | __ negq(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2601 | break; |
| 2602 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2603 | case DataType::Type::kFloat32: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2604 | DCHECK(in.Equals(out)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2605 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2606 | // Implement float negation with an exclusive or with value |
| 2607 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2608 | // single-precision floating-point number). |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2609 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2610 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2611 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2612 | } |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2613 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2614 | case DataType::Type::kFloat64: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2615 | DCHECK(in.Equals(out)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2616 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2617 | // Implement double negation with an exclusive or with value |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2618 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2619 | // a double-precision floating-point number). |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2620 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2621 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2622 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2623 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2624 | |
| 2625 | default: |
| 2626 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2627 | } |
| 2628 | } |
| 2629 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2630 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2631 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2632 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2633 | DataType::Type result_type = conversion->GetResultType(); |
| 2634 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2635 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2636 | << input_type << " -> " << result_type; |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2637 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2638 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2639 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2640 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2641 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2642 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2643 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2644 | locations->SetInAt(0, Location::Any()); |
| 2645 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2646 | break; |
| 2647 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2648 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2649 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2650 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2651 | locations->SetInAt(0, Location::Any()); |
| 2652 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2653 | break; |
| 2654 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2655 | case DataType::Type::kFloat32: |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2656 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2657 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2658 | break; |
| 2659 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2660 | case DataType::Type::kFloat64: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2661 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2662 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2663 | break; |
| 2664 | |
| 2665 | default: |
| 2666 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2667 | << " to " << result_type; |
| 2668 | } |
| 2669 | break; |
| 2670 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2671 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2672 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2673 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2674 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2675 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2676 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2677 | case DataType::Type::kInt16: |
| 2678 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2679 | // TODO: We would benefit from a (to-be-implemented) |
| 2680 | // Location::RegisterOrStackSlot requirement for this input. |
| 2681 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2682 | locations->SetOut(Location::RequiresRegister()); |
| 2683 | break; |
| 2684 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2685 | case DataType::Type::kFloat32: |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2686 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2687 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2688 | break; |
| 2689 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2690 | case DataType::Type::kFloat64: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2691 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2692 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2693 | break; |
| 2694 | |
| 2695 | default: |
| 2696 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2697 | << " to " << result_type; |
| 2698 | } |
| 2699 | break; |
| 2700 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2701 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2702 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2703 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2704 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2705 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2706 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2707 | case DataType::Type::kInt16: |
| 2708 | case DataType::Type::kInt32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2709 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2710 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2711 | break; |
| 2712 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2713 | case DataType::Type::kInt64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2714 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2715 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2716 | break; |
| 2717 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2718 | case DataType::Type::kFloat64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2719 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2720 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2721 | break; |
| 2722 | |
| 2723 | default: |
| 2724 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2725 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2726 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2727 | break; |
| 2728 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2729 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2730 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2731 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2732 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2733 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2734 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2735 | case DataType::Type::kInt16: |
| 2736 | case DataType::Type::kInt32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2737 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2738 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2739 | break; |
| 2740 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2741 | case DataType::Type::kInt64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2742 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2743 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2744 | break; |
| 2745 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2746 | case DataType::Type::kFloat32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2747 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2748 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2749 | break; |
| 2750 | |
| 2751 | default: |
| 2752 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2753 | << " to " << result_type; |
| 2754 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2755 | break; |
| 2756 | |
| 2757 | default: |
| 2758 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2759 | << " to " << result_type; |
| 2760 | } |
| 2761 | } |
| 2762 | |
| 2763 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2764 | LocationSummary* locations = conversion->GetLocations(); |
| 2765 | Location out = locations->Out(); |
| 2766 | Location in = locations->InAt(0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2767 | DataType::Type result_type = conversion->GetResultType(); |
| 2768 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2769 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2770 | << input_type << " -> " << result_type; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2771 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2772 | case DataType::Type::kUint8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2773 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2774 | case DataType::Type::kInt8: |
| 2775 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2776 | case DataType::Type::kInt16: |
| 2777 | case DataType::Type::kInt32: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2778 | case DataType::Type::kInt64: |
| 2779 | if (in.IsRegister()) { |
| 2780 | __ movzxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 2781 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 2782 | __ movzxb(out.AsRegister<CpuRegister>(), |
| 2783 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2784 | } else { |
| 2785 | __ movl(out.AsRegister<CpuRegister>(), |
| 2786 | Immediate(static_cast<uint8_t>(Int64FromConstant(in.GetConstant())))); |
| 2787 | } |
| 2788 | break; |
| 2789 | |
| 2790 | default: |
| 2791 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2792 | << " to " << result_type; |
| 2793 | } |
| 2794 | break; |
| 2795 | |
| 2796 | case DataType::Type::kInt8: |
| 2797 | switch (input_type) { |
| 2798 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2799 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2800 | case DataType::Type::kInt16: |
| 2801 | case DataType::Type::kInt32: |
| 2802 | case DataType::Type::kInt64: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2803 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2804 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2805 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2806 | __ movsxb(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2807 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2808 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2809 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2810 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2811 | } |
| 2812 | break; |
| 2813 | |
| 2814 | default: |
| 2815 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2816 | << " to " << result_type; |
| 2817 | } |
| 2818 | break; |
| 2819 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2820 | case DataType::Type::kUint16: |
| 2821 | switch (input_type) { |
| 2822 | case DataType::Type::kInt8: |
| 2823 | case DataType::Type::kInt16: |
| 2824 | case DataType::Type::kInt32: |
| 2825 | case DataType::Type::kInt64: |
| 2826 | if (in.IsRegister()) { |
| 2827 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 2828 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 2829 | __ movzxw(out.AsRegister<CpuRegister>(), |
| 2830 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2831 | } else { |
| 2832 | __ movl(out.AsRegister<CpuRegister>(), |
| 2833 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
| 2834 | } |
| 2835 | break; |
| 2836 | |
| 2837 | default: |
| 2838 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2839 | << " to " << result_type; |
| 2840 | } |
| 2841 | break; |
| 2842 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2843 | case DataType::Type::kInt16: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2844 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2845 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2846 | case DataType::Type::kInt32: |
| 2847 | case DataType::Type::kInt64: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2848 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2849 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2850 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2851 | __ movsxw(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2852 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2853 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2854 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2855 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2856 | } |
| 2857 | break; |
| 2858 | |
| 2859 | default: |
| 2860 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2861 | << " to " << result_type; |
| 2862 | } |
| 2863 | break; |
| 2864 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2865 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2866 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2867 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2868 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2869 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2870 | } else if (in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2871 | __ movl(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2872 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2873 | } else { |
| 2874 | DCHECK(in.IsConstant()); |
| 2875 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2876 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2877 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2878 | } |
| 2879 | break; |
| 2880 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2881 | case DataType::Type::kFloat32: { |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2882 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2883 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2884 | NearLabel done, nan; |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2885 | |
| 2886 | __ movl(output, Immediate(kPrimIntMax)); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2887 | // if input >= (float)INT_MAX goto done |
| 2888 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2889 | __ j(kAboveEqual, &done); |
| 2890 | // if input == NaN goto nan |
| 2891 | __ j(kUnordered, &nan); |
| 2892 | // output = float-to-int-truncate(input) |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2893 | __ cvttss2si(output, input, false); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2894 | __ jmp(&done); |
| 2895 | __ Bind(&nan); |
| 2896 | // output = 0 |
| 2897 | __ xorl(output, output); |
| 2898 | __ Bind(&done); |
| 2899 | break; |
| 2900 | } |
| 2901 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2902 | case DataType::Type::kFloat64: { |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2903 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2904 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2905 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2906 | |
| 2907 | __ movl(output, Immediate(kPrimIntMax)); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2908 | // if input >= (double)INT_MAX goto done |
| 2909 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2910 | __ j(kAboveEqual, &done); |
| 2911 | // if input == NaN goto nan |
| 2912 | __ j(kUnordered, &nan); |
| 2913 | // output = double-to-int-truncate(input) |
| 2914 | __ cvttsd2si(output, input); |
| 2915 | __ jmp(&done); |
| 2916 | __ Bind(&nan); |
| 2917 | // output = 0 |
| 2918 | __ xorl(output, output); |
| 2919 | __ Bind(&done); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2920 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2921 | } |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2922 | |
| 2923 | default: |
| 2924 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2925 | << " to " << result_type; |
| 2926 | } |
| 2927 | break; |
| 2928 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2929 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2930 | switch (input_type) { |
| 2931 | DCHECK(out.IsRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2932 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2933 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2934 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2935 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2936 | case DataType::Type::kInt16: |
| 2937 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2938 | DCHECK(in.IsRegister()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2939 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2940 | break; |
| 2941 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2942 | case DataType::Type::kFloat32: { |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2943 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2944 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2945 | NearLabel done, nan; |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2946 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2947 | codegen_->Load64BitValue(output, kPrimLongMax); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2948 | // if input >= (float)LONG_MAX goto done |
| 2949 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2950 | __ j(kAboveEqual, &done); |
| 2951 | // if input == NaN goto nan |
| 2952 | __ j(kUnordered, &nan); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2953 | // output = float-to-long-truncate(input) |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2954 | __ cvttss2si(output, input, true); |
| 2955 | __ jmp(&done); |
| 2956 | __ Bind(&nan); |
| 2957 | // output = 0 |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2958 | __ xorl(output, output); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2959 | __ Bind(&done); |
| 2960 | break; |
| 2961 | } |
| 2962 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2963 | case DataType::Type::kFloat64: { |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2964 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2965 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2966 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2967 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2968 | codegen_->Load64BitValue(output, kPrimLongMax); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2969 | // if input >= (double)LONG_MAX goto done |
| 2970 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2971 | __ j(kAboveEqual, &done); |
| 2972 | // if input == NaN goto nan |
| 2973 | __ j(kUnordered, &nan); |
| 2974 | // output = double-to-long-truncate(input) |
| 2975 | __ cvttsd2si(output, input, true); |
| 2976 | __ jmp(&done); |
| 2977 | __ Bind(&nan); |
| 2978 | // output = 0 |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2979 | __ xorl(output, output); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2980 | __ Bind(&done); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2981 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2982 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2983 | |
| 2984 | default: |
| 2985 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2986 | << " to " << result_type; |
| 2987 | } |
| 2988 | break; |
| 2989 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2990 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2991 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2992 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2993 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2994 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2995 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2996 | case DataType::Type::kInt16: |
| 2997 | case DataType::Type::kInt32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2998 | if (in.IsRegister()) { |
| 2999 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3000 | } else if (in.IsConstant()) { |
| 3001 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3002 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3003 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3004 | } else { |
| 3005 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3006 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3007 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3008 | break; |
| 3009 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3010 | case DataType::Type::kInt64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3011 | if (in.IsRegister()) { |
| 3012 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3013 | } else if (in.IsConstant()) { |
| 3014 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3015 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 3016 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3017 | } else { |
| 3018 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3019 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3020 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3021 | break; |
| 3022 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3023 | case DataType::Type::kFloat64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3024 | if (in.IsFpuRegister()) { |
| 3025 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3026 | } else if (in.IsConstant()) { |
| 3027 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 3028 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3029 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3030 | } else { |
| 3031 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 3032 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3033 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3034 | break; |
| 3035 | |
| 3036 | default: |
| 3037 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3038 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3039 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3040 | break; |
| 3041 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3042 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3043 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3044 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3045 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3046 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3047 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3048 | case DataType::Type::kInt16: |
| 3049 | case DataType::Type::kInt32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3050 | if (in.IsRegister()) { |
| 3051 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3052 | } else if (in.IsConstant()) { |
| 3053 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3054 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3055 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3056 | } else { |
| 3057 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3058 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3059 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3060 | break; |
| 3061 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3062 | case DataType::Type::kInt64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3063 | if (in.IsRegister()) { |
| 3064 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3065 | } else if (in.IsConstant()) { |
| 3066 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3067 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3068 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3069 | } else { |
| 3070 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3071 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3072 | } |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3073 | break; |
| 3074 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3075 | case DataType::Type::kFloat32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3076 | if (in.IsFpuRegister()) { |
| 3077 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3078 | } else if (in.IsConstant()) { |
| 3079 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3080 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3081 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3082 | } else { |
| 3083 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3084 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3085 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3086 | break; |
| 3087 | |
| 3088 | default: |
| 3089 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3090 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3091 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3092 | break; |
| 3093 | |
| 3094 | default: |
| 3095 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3096 | << " to " << result_type; |
| 3097 | } |
| 3098 | } |
| 3099 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3100 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3101 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3102 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3103 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3104 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3105 | locations->SetInAt(0, Location::RequiresRegister()); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3106 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3107 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3108 | break; |
| 3109 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3110 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3111 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3112 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3113 | // 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] | 3114 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3115 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3116 | break; |
| 3117 | } |
| 3118 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3119 | case DataType::Type::kFloat64: |
| 3120 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3121 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3122 | locations->SetInAt(1, Location::Any()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3123 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3124 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3125 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3126 | |
| 3127 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3128 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3129 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3133 | LocationSummary* locations = add->GetLocations(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3134 | Location first = locations->InAt(0); |
| 3135 | Location second = locations->InAt(1); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3136 | Location out = locations->Out(); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3137 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3138 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3139 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3140 | if (second.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3141 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3142 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3143 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3144 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3145 | } else { |
| 3146 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3147 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3148 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3149 | } else if (second.IsConstant()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3150 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3151 | __ addl(out.AsRegister<CpuRegister>(), |
| 3152 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3153 | } else { |
| 3154 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3155 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3156 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3157 | } else { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3158 | DCHECK(first.Equals(locations->Out())); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3159 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3160 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3161 | break; |
| 3162 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3163 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3164 | case DataType::Type::kInt64: { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3165 | if (second.IsRegister()) { |
| 3166 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3167 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3168 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3169 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3170 | } else { |
| 3171 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3172 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3173 | } |
| 3174 | } else { |
| 3175 | DCHECK(second.IsConstant()); |
| 3176 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3177 | int32_t int32_value = Low32Bits(value); |
| 3178 | DCHECK_EQ(int32_value, value); |
| 3179 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3180 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3181 | } else { |
| 3182 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3183 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3184 | } |
| 3185 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3186 | break; |
| 3187 | } |
| 3188 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3189 | case DataType::Type::kFloat32: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3190 | if (second.IsFpuRegister()) { |
| 3191 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3192 | } else if (second.IsConstant()) { |
| 3193 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3194 | codegen_->LiteralFloatAddress( |
| 3195 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3196 | } else { |
| 3197 | DCHECK(second.IsStackSlot()); |
| 3198 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3199 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3200 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3201 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3202 | } |
| 3203 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3204 | case DataType::Type::kFloat64: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3205 | if (second.IsFpuRegister()) { |
| 3206 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3207 | } else if (second.IsConstant()) { |
| 3208 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3209 | codegen_->LiteralDoubleAddress( |
| 3210 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3211 | } else { |
| 3212 | DCHECK(second.IsDoubleStackSlot()); |
| 3213 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3214 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3215 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3216 | break; |
| 3217 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3218 | |
| 3219 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3220 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3221 | } |
| 3222 | } |
| 3223 | |
| 3224 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3225 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3226 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3227 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3228 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3229 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3230 | locations->SetInAt(1, Location::Any()); |
| 3231 | locations->SetOut(Location::SameAsFirstInput()); |
| 3232 | break; |
| 3233 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3234 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3235 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3236 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3237 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3238 | break; |
| 3239 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3240 | case DataType::Type::kFloat32: |
| 3241 | case DataType::Type::kFloat64: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3242 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3243 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3244 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3245 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3246 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3247 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3248 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3249 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3253 | LocationSummary* locations = sub->GetLocations(); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3254 | Location first = locations->InAt(0); |
| 3255 | Location second = locations->InAt(1); |
| 3256 | DCHECK(first.Equals(locations->Out())); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3257 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3258 | case DataType::Type::kInt32: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3259 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3260 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3261 | } else if (second.IsConstant()) { |
| 3262 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3263 | __ subl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3264 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3265 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3266 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3267 | break; |
| 3268 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3269 | case DataType::Type::kInt64: { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3270 | if (second.IsConstant()) { |
| 3271 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3272 | DCHECK(IsInt<32>(value)); |
| 3273 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3274 | } else { |
| 3275 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3276 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3277 | break; |
| 3278 | } |
| 3279 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3280 | case DataType::Type::kFloat32: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3281 | if (second.IsFpuRegister()) { |
| 3282 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3283 | } else if (second.IsConstant()) { |
| 3284 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3285 | codegen_->LiteralFloatAddress( |
| 3286 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3287 | } else { |
| 3288 | DCHECK(second.IsStackSlot()); |
| 3289 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3290 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3291 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3292 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3293 | } |
| 3294 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3295 | case DataType::Type::kFloat64: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3296 | if (second.IsFpuRegister()) { |
| 3297 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3298 | } else if (second.IsConstant()) { |
| 3299 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3300 | codegen_->LiteralDoubleAddress( |
| 3301 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3302 | } else { |
| 3303 | DCHECK(second.IsDoubleStackSlot()); |
| 3304 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3305 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3306 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3307 | break; |
| 3308 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3309 | |
| 3310 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3311 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3312 | } |
| 3313 | } |
| 3314 | |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3315 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3316 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3317 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3318 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3319 | case DataType::Type::kInt32: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3320 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3321 | locations->SetInAt(1, Location::Any()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3322 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3323 | // Can use 3 operand multiply. |
| 3324 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3325 | } else { |
| 3326 | locations->SetOut(Location::SameAsFirstInput()); |
| 3327 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3328 | break; |
| 3329 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3330 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3331 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3332 | locations->SetInAt(1, Location::Any()); |
| 3333 | if (mul->InputAt(1)->IsLongConstant() && |
| 3334 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3335 | // Can use 3 operand multiply. |
| 3336 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3337 | } else { |
| 3338 | locations->SetOut(Location::SameAsFirstInput()); |
| 3339 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3340 | break; |
| 3341 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3342 | case DataType::Type::kFloat32: |
| 3343 | case DataType::Type::kFloat64: { |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3344 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3345 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3346 | locations->SetOut(Location::SameAsFirstInput()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3347 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3348 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3349 | |
| 3350 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3351 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3352 | } |
| 3353 | } |
| 3354 | |
| 3355 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3356 | LocationSummary* locations = mul->GetLocations(); |
| 3357 | Location first = locations->InAt(0); |
| 3358 | Location second = locations->InAt(1); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3359 | Location out = locations->Out(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3360 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3361 | case DataType::Type::kInt32: |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3362 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3363 | // problems where the output may not be the same as the first operand. |
| 3364 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3365 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3366 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3367 | } else if (second.IsRegister()) { |
| 3368 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3369 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3370 | } else { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3371 | DCHECK(first.Equals(out)); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3372 | DCHECK(second.IsStackSlot()); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3373 | __ imull(first.AsRegister<CpuRegister>(), |
| 3374 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3375 | } |
| 3376 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3377 | case DataType::Type::kInt64: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3378 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3379 | // problems where the output may not be the same as the first operand. |
| 3380 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3381 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3382 | if (IsInt<32>(value)) { |
| 3383 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3384 | Immediate(static_cast<int32_t>(value))); |
| 3385 | } else { |
| 3386 | // Have to use the constant area. |
| 3387 | DCHECK(first.Equals(out)); |
| 3388 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3389 | } |
| 3390 | } else if (second.IsRegister()) { |
| 3391 | DCHECK(first.Equals(out)); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3392 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3393 | } else { |
| 3394 | DCHECK(second.IsDoubleStackSlot()); |
| 3395 | DCHECK(first.Equals(out)); |
| 3396 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3397 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3398 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3399 | break; |
| 3400 | } |
| 3401 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3402 | case DataType::Type::kFloat32: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3403 | DCHECK(first.Equals(out)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3404 | if (second.IsFpuRegister()) { |
| 3405 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3406 | } else if (second.IsConstant()) { |
| 3407 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3408 | codegen_->LiteralFloatAddress( |
| 3409 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3410 | } else { |
| 3411 | DCHECK(second.IsStackSlot()); |
| 3412 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3413 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3414 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3415 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3416 | } |
| 3417 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3418 | case DataType::Type::kFloat64: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3419 | DCHECK(first.Equals(out)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3420 | if (second.IsFpuRegister()) { |
| 3421 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3422 | } else if (second.IsConstant()) { |
| 3423 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3424 | codegen_->LiteralDoubleAddress( |
| 3425 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3426 | } else { |
| 3427 | DCHECK(second.IsDoubleStackSlot()); |
| 3428 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3429 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3430 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3431 | break; |
| 3432 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3433 | |
| 3434 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3435 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3436 | } |
| 3437 | } |
| 3438 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3439 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3440 | uint32_t stack_adjustment, bool is_float) { |
| 3441 | if (source.IsStackSlot()) { |
| 3442 | DCHECK(is_float); |
| 3443 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3444 | } else if (source.IsDoubleStackSlot()) { |
| 3445 | DCHECK(!is_float); |
| 3446 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3447 | } else { |
| 3448 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3449 | if (is_float) { |
| 3450 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3451 | codegen_->Move(stack_temp, source); |
| 3452 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3453 | } else { |
| 3454 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3455 | codegen_->Move(stack_temp, source); |
| 3456 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3457 | } |
| 3458 | } |
| 3459 | } |
| 3460 | |
| 3461 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3462 | DataType::Type type = rem->GetResultType(); |
| 3463 | bool is_float = type == DataType::Type::kFloat32; |
| 3464 | size_t elem_size = DataType::Size(type); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3465 | LocationSummary* locations = rem->GetLocations(); |
| 3466 | Location first = locations->InAt(0); |
| 3467 | Location second = locations->InAt(1); |
| 3468 | Location out = locations->Out(); |
| 3469 | |
| 3470 | // Create stack space for 2 elements. |
| 3471 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3472 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3473 | |
| 3474 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3475 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3476 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3477 | |
| 3478 | // Loop doing FPREM until we stabilize. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3479 | NearLabel retry; |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3480 | __ Bind(&retry); |
| 3481 | __ fprem(); |
| 3482 | |
| 3483 | // Move FP status to AX. |
| 3484 | __ fstsw(); |
| 3485 | |
| 3486 | // And see if the argument reduction is complete. This is signaled by the |
| 3487 | // C2 FPU flag bit set to 0. |
| 3488 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3489 | __ j(kNotEqual, &retry); |
| 3490 | |
| 3491 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3492 | // Store FP top of stack to real stack. |
| 3493 | if (is_float) { |
| 3494 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3495 | } else { |
| 3496 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3497 | } |
| 3498 | |
| 3499 | // Pop the 2 items from the FP stack. |
| 3500 | __ fucompp(); |
| 3501 | |
| 3502 | // Load the value from the stack into an XMM register. |
| 3503 | DCHECK(out.IsFpuRegister()) << out; |
| 3504 | if (is_float) { |
| 3505 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3506 | } else { |
| 3507 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3508 | } |
| 3509 | |
| 3510 | // And remove the temporary stack space we allocated. |
| 3511 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3512 | } |
| 3513 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3514 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3515 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3516 | |
| 3517 | LocationSummary* locations = instruction->GetLocations(); |
| 3518 | Location second = locations->InAt(1); |
| 3519 | DCHECK(second.IsConstant()); |
| 3520 | |
| 3521 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3522 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3523 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3524 | |
| 3525 | DCHECK(imm == 1 || imm == -1); |
| 3526 | |
| 3527 | switch (instruction->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3528 | case DataType::Type::kInt32: { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3529 | if (instruction->IsRem()) { |
| 3530 | __ xorl(output_register, output_register); |
| 3531 | } else { |
| 3532 | __ movl(output_register, input_register); |
| 3533 | if (imm == -1) { |
| 3534 | __ negl(output_register); |
| 3535 | } |
| 3536 | } |
| 3537 | break; |
| 3538 | } |
| 3539 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3540 | case DataType::Type::kInt64: { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3541 | if (instruction->IsRem()) { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3542 | __ xorl(output_register, output_register); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3543 | } else { |
| 3544 | __ movq(output_register, input_register); |
| 3545 | if (imm == -1) { |
| 3546 | __ negq(output_register); |
| 3547 | } |
| 3548 | } |
| 3549 | break; |
| 3550 | } |
| 3551 | |
| 3552 | default: |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3553 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3554 | } |
| 3555 | } |
| 3556 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3557 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3558 | LocationSummary* locations = instruction->GetLocations(); |
| 3559 | Location second = locations->InAt(1); |
| 3560 | |
| 3561 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3562 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3563 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3564 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3565 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3566 | uint64_t abs_imm = AbsOrMin(imm); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3567 | |
| 3568 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3569 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3570 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3571 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3572 | __ testl(numerator, numerator); |
| 3573 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3574 | int shift = CTZ(imm); |
| 3575 | __ sarl(tmp, Immediate(shift)); |
| 3576 | |
| 3577 | if (imm < 0) { |
| 3578 | __ negl(tmp); |
| 3579 | } |
| 3580 | |
| 3581 | __ movl(output_register, tmp); |
| 3582 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3583 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3584 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3585 | |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3586 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3587 | __ addq(rdx, numerator); |
| 3588 | __ testq(numerator, numerator); |
| 3589 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3590 | int shift = CTZ(imm); |
| 3591 | __ sarq(rdx, Immediate(shift)); |
| 3592 | |
| 3593 | if (imm < 0) { |
| 3594 | __ negq(rdx); |
| 3595 | } |
| 3596 | |
| 3597 | __ movq(output_register, rdx); |
| 3598 | } |
| 3599 | } |
| 3600 | |
| 3601 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3602 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3603 | |
| 3604 | LocationSummary* locations = instruction->GetLocations(); |
| 3605 | Location second = locations->InAt(1); |
| 3606 | |
| 3607 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3608 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3609 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3610 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3611 | : locations->Out().AsRegister<CpuRegister>(); |
| 3612 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3613 | |
| 3614 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3615 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3616 | if (instruction->IsDiv()) { |
| 3617 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3618 | } else { |
| 3619 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3620 | } |
| 3621 | |
| 3622 | int64_t magic; |
| 3623 | int shift; |
| 3624 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3625 | // TODO: can these branches be written as one? |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3626 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3627 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3628 | |
| 3629 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3630 | |
| 3631 | __ movl(numerator, eax); |
| 3632 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3633 | __ movl(eax, Immediate(magic)); |
| 3634 | __ imull(numerator); |
| 3635 | |
| 3636 | if (imm > 0 && magic < 0) { |
| 3637 | __ addl(edx, numerator); |
| 3638 | } else if (imm < 0 && magic > 0) { |
| 3639 | __ subl(edx, numerator); |
| 3640 | } |
| 3641 | |
| 3642 | if (shift != 0) { |
| 3643 | __ sarl(edx, Immediate(shift)); |
| 3644 | } |
| 3645 | |
| 3646 | __ movl(eax, edx); |
| 3647 | __ shrl(edx, Immediate(31)); |
| 3648 | __ addl(edx, eax); |
| 3649 | |
| 3650 | if (instruction->IsRem()) { |
| 3651 | __ movl(eax, numerator); |
| 3652 | __ imull(edx, Immediate(imm)); |
| 3653 | __ subl(eax, edx); |
| 3654 | __ movl(edx, eax); |
| 3655 | } else { |
| 3656 | __ movl(eax, edx); |
| 3657 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3658 | } else { |
| 3659 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3660 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3661 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3662 | |
| 3663 | CpuRegister rax = eax; |
| 3664 | CpuRegister rdx = edx; |
| 3665 | |
| 3666 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3667 | |
| 3668 | // Save the numerator. |
| 3669 | __ movq(numerator, rax); |
| 3670 | |
| 3671 | // RAX = magic |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3672 | codegen_->Load64BitValue(rax, magic); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3673 | |
| 3674 | // RDX:RAX = magic * numerator |
| 3675 | __ imulq(numerator); |
| 3676 | |
| 3677 | if (imm > 0 && magic < 0) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3678 | // RDX += numerator |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3679 | __ addq(rdx, numerator); |
| 3680 | } else if (imm < 0 && magic > 0) { |
| 3681 | // RDX -= numerator |
| 3682 | __ subq(rdx, numerator); |
| 3683 | } |
| 3684 | |
| 3685 | // Shift if needed. |
| 3686 | if (shift != 0) { |
| 3687 | __ sarq(rdx, Immediate(shift)); |
| 3688 | } |
| 3689 | |
| 3690 | // RDX += 1 if RDX < 0 |
| 3691 | __ movq(rax, rdx); |
| 3692 | __ shrq(rdx, Immediate(63)); |
| 3693 | __ addq(rdx, rax); |
| 3694 | |
| 3695 | if (instruction->IsRem()) { |
| 3696 | __ movq(rax, numerator); |
| 3697 | |
| 3698 | if (IsInt<32>(imm)) { |
| 3699 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3700 | } else { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3701 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | __ subq(rax, rdx); |
| 3705 | __ movq(rdx, rax); |
| 3706 | } else { |
| 3707 | __ movq(rax, rdx); |
| 3708 | } |
| 3709 | } |
| 3710 | } |
| 3711 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3712 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3713 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3714 | DataType::Type type = instruction->GetResultType(); |
| 3715 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3716 | |
| 3717 | bool is_div = instruction->IsDiv(); |
| 3718 | LocationSummary* locations = instruction->GetLocations(); |
| 3719 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3720 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3721 | Location second = locations->InAt(1); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3722 | |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3723 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3724 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3725 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3726 | if (second.IsConstant()) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3727 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3728 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3729 | if (imm == 0) { |
| 3730 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3731 | } else if (imm == 1 || imm == -1) { |
| 3732 | DivRemOneOrMinusOne(instruction); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3733 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3734 | DivByPowerOfTwo(instruction->AsDiv()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3735 | } else { |
| 3736 | DCHECK(imm <= -2 || imm >= 2); |
| 3737 | GenerateDivRemWithAnyConstant(instruction); |
| 3738 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3739 | } else { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3740 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3741 | new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86_64( |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3742 | instruction, out.AsRegister(), type, is_div); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3743 | codegen_->AddSlowPath(slow_path); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3744 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3745 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3746 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3747 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3748 | // so it's safe to just use negl instead of more complex comparisons. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3749 | if (type == DataType::Type::kInt32) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3750 | __ cmpl(second_reg, Immediate(-1)); |
| 3751 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3752 | // edx:eax <- sign-extended of eax |
| 3753 | __ cdq(); |
| 3754 | // eax = quotient, edx = remainder |
| 3755 | __ idivl(second_reg); |
| 3756 | } else { |
| 3757 | __ cmpq(second_reg, Immediate(-1)); |
| 3758 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3759 | // rdx:rax <- sign-extended of rax |
| 3760 | __ cqo(); |
| 3761 | // rax = quotient, rdx = remainder |
| 3762 | __ idivq(second_reg); |
| 3763 | } |
| 3764 | __ Bind(slow_path->GetExitLabel()); |
| 3765 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3766 | } |
| 3767 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3768 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3769 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3770 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3771 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3772 | case DataType::Type::kInt32: |
| 3773 | case DataType::Type::kInt64: { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3774 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3775 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3776 | locations->SetOut(Location::SameAsFirstInput()); |
| 3777 | // Intel uses edx:eax as the dividend. |
| 3778 | locations->AddTemp(Location::RegisterLocation(RDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3779 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3780 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3781 | // output and request another temp. |
| 3782 | if (div->InputAt(1)->IsConstant()) { |
| 3783 | locations->AddTemp(Location::RequiresRegister()); |
| 3784 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3785 | break; |
| 3786 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3787 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3788 | case DataType::Type::kFloat32: |
| 3789 | case DataType::Type::kFloat64: { |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3790 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3791 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3792 | locations->SetOut(Location::SameAsFirstInput()); |
| 3793 | break; |
| 3794 | } |
| 3795 | |
| 3796 | default: |
| 3797 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3798 | } |
| 3799 | } |
| 3800 | |
| 3801 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3802 | LocationSummary* locations = div->GetLocations(); |
| 3803 | Location first = locations->InAt(0); |
| 3804 | Location second = locations->InAt(1); |
| 3805 | DCHECK(first.Equals(locations->Out())); |
| 3806 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3807 | DataType::Type type = div->GetResultType(); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3808 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3809 | case DataType::Type::kInt32: |
| 3810 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3811 | GenerateDivRemIntegral(div); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3812 | break; |
| 3813 | } |
| 3814 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3815 | case DataType::Type::kFloat32: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3816 | if (second.IsFpuRegister()) { |
| 3817 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3818 | } else if (second.IsConstant()) { |
| 3819 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3820 | codegen_->LiteralFloatAddress( |
| 3821 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3822 | } else { |
| 3823 | DCHECK(second.IsStackSlot()); |
| 3824 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3825 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3826 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3827 | break; |
| 3828 | } |
| 3829 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3830 | case DataType::Type::kFloat64: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3831 | if (second.IsFpuRegister()) { |
| 3832 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3833 | } else if (second.IsConstant()) { |
| 3834 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3835 | codegen_->LiteralDoubleAddress( |
| 3836 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3837 | } else { |
| 3838 | DCHECK(second.IsDoubleStackSlot()); |
| 3839 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3840 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3841 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3842 | break; |
| 3843 | } |
| 3844 | |
| 3845 | default: |
| 3846 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3847 | } |
| 3848 | } |
| 3849 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3850 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3851 | DataType::Type type = rem->GetResultType(); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3852 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3853 | new (GetGraph()->GetAllocator()) LocationSummary(rem, LocationSummary::kNoCall); |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3854 | |
| 3855 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3856 | case DataType::Type::kInt32: |
| 3857 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3858 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3859 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3860 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3861 | locations->SetOut(Location::RegisterLocation(RDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3862 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3863 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3864 | // output and request another temp. |
| 3865 | if (rem->InputAt(1)->IsConstant()) { |
| 3866 | locations->AddTemp(Location::RequiresRegister()); |
| 3867 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3868 | break; |
| 3869 | } |
| 3870 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3871 | case DataType::Type::kFloat32: |
| 3872 | case DataType::Type::kFloat64: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3873 | locations->SetInAt(0, Location::Any()); |
| 3874 | locations->SetInAt(1, Location::Any()); |
| 3875 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3876 | locations->AddTemp(Location::RegisterLocation(RAX)); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3877 | break; |
| 3878 | } |
| 3879 | |
| 3880 | default: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3881 | LOG(FATAL) << "Unexpected rem type " << type; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3882 | } |
| 3883 | } |
| 3884 | |
| 3885 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3886 | DataType::Type type = rem->GetResultType(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3887 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3888 | case DataType::Type::kInt32: |
| 3889 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3890 | GenerateDivRemIntegral(rem); |
| 3891 | break; |
| 3892 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3893 | case DataType::Type::kFloat32: |
| 3894 | case DataType::Type::kFloat64: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3895 | GenerateRemFP(rem); |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3896 | break; |
| 3897 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3898 | default: |
| 3899 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3900 | } |
| 3901 | } |
| 3902 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3903 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 3904 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 3905 | switch (minmax->GetResultType()) { |
| 3906 | case DataType::Type::kInt32: |
| 3907 | case DataType::Type::kInt64: |
| 3908 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3909 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3910 | locations->SetOut(Location::SameAsFirstInput()); |
| 3911 | break; |
| 3912 | case DataType::Type::kFloat32: |
| 3913 | case DataType::Type::kFloat64: |
| 3914 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3915 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3916 | // The following is sub-optimal, but all we can do for now. It would be fine to also accept |
| 3917 | // the second input to be the output (we can simply swap inputs). |
| 3918 | locations->SetOut(Location::SameAsFirstInput()); |
| 3919 | break; |
| 3920 | default: |
| 3921 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 3922 | } |
| 3923 | } |
| 3924 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 3925 | void InstructionCodeGeneratorX86_64::GenerateMinMaxInt(LocationSummary* locations, |
| 3926 | bool is_min, |
| 3927 | DataType::Type type) { |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3928 | Location op1_loc = locations->InAt(0); |
| 3929 | Location op2_loc = locations->InAt(1); |
| 3930 | |
| 3931 | // Shortcut for same input locations. |
| 3932 | if (op1_loc.Equals(op2_loc)) { |
| 3933 | // Can return immediately, as op1_loc == out_loc. |
| 3934 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 3935 | // a copy here. |
| 3936 | DCHECK(locations->Out().Equals(op1_loc)); |
| 3937 | return; |
| 3938 | } |
| 3939 | |
| 3940 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3941 | CpuRegister op2 = op2_loc.AsRegister<CpuRegister>(); |
| 3942 | |
| 3943 | // (out := op1) |
| 3944 | // out <=? op2 |
| 3945 | // if out is min jmp done |
| 3946 | // out := op2 |
| 3947 | // done: |
| 3948 | |
| 3949 | if (type == DataType::Type::kInt64) { |
| 3950 | __ cmpq(out, op2); |
| 3951 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ true); |
| 3952 | } else { |
| 3953 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 3954 | __ cmpl(out, op2); |
| 3955 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ false); |
| 3956 | } |
| 3957 | } |
| 3958 | |
| 3959 | void InstructionCodeGeneratorX86_64::GenerateMinMaxFP(LocationSummary* locations, |
| 3960 | bool is_min, |
| 3961 | DataType::Type type) { |
| 3962 | Location op1_loc = locations->InAt(0); |
| 3963 | Location op2_loc = locations->InAt(1); |
| 3964 | Location out_loc = locations->Out(); |
| 3965 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 3966 | |
| 3967 | // Shortcut for same input locations. |
| 3968 | if (op1_loc.Equals(op2_loc)) { |
| 3969 | DCHECK(out_loc.Equals(op1_loc)); |
| 3970 | return; |
| 3971 | } |
| 3972 | |
| 3973 | // (out := op1) |
| 3974 | // out <=? op2 |
| 3975 | // if Nan jmp Nan_label |
| 3976 | // if out is min jmp done |
| 3977 | // if op2 is min jmp op2_label |
| 3978 | // handle -0/+0 |
| 3979 | // jmp done |
| 3980 | // Nan_label: |
| 3981 | // out := NaN |
| 3982 | // op2_label: |
| 3983 | // out := op2 |
| 3984 | // done: |
| 3985 | // |
| 3986 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 3987 | // |
| 3988 | // TODO: This is straight from Quick. Make NaN an out-of-line slowpath? |
| 3989 | |
| 3990 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 3991 | |
| 3992 | NearLabel nan, done, op2_label; |
| 3993 | if (type == DataType::Type::kFloat64) { |
| 3994 | __ ucomisd(out, op2); |
| 3995 | } else { |
| 3996 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 3997 | __ ucomiss(out, op2); |
| 3998 | } |
| 3999 | |
| 4000 | __ j(Condition::kParityEven, &nan); |
| 4001 | |
| 4002 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4003 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4004 | |
| 4005 | // Handle 0.0/-0.0. |
| 4006 | if (is_min) { |
| 4007 | if (type == DataType::Type::kFloat64) { |
| 4008 | __ orpd(out, op2); |
| 4009 | } else { |
| 4010 | __ orps(out, op2); |
| 4011 | } |
| 4012 | } else { |
| 4013 | if (type == DataType::Type::kFloat64) { |
| 4014 | __ andpd(out, op2); |
| 4015 | } else { |
| 4016 | __ andps(out, op2); |
| 4017 | } |
| 4018 | } |
| 4019 | __ jmp(&done); |
| 4020 | |
| 4021 | // NaN handling. |
| 4022 | __ Bind(&nan); |
| 4023 | if (type == DataType::Type::kFloat64) { |
| 4024 | __ movsd(out, codegen_->LiteralInt64Address(INT64_C(0x7FF8000000000000))); |
| 4025 | } else { |
| 4026 | __ movss(out, codegen_->LiteralInt32Address(INT32_C(0x7FC00000))); |
| 4027 | } |
| 4028 | __ jmp(&done); |
| 4029 | |
| 4030 | // out := op2; |
| 4031 | __ Bind(&op2_label); |
| 4032 | if (type == DataType::Type::kFloat64) { |
| 4033 | __ movsd(out, op2); |
| 4034 | } else { |
| 4035 | __ movss(out, op2); |
| 4036 | } |
| 4037 | |
| 4038 | // Done. |
| 4039 | __ Bind(&done); |
| 4040 | } |
| 4041 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4042 | void InstructionCodeGeneratorX86_64::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4043 | DataType::Type type = minmax->GetResultType(); |
| 4044 | switch (type) { |
| 4045 | case DataType::Type::kInt32: |
| 4046 | case DataType::Type::kInt64: |
| 4047 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4048 | break; |
| 4049 | case DataType::Type::kFloat32: |
| 4050 | case DataType::Type::kFloat64: |
| 4051 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4052 | break; |
| 4053 | default: |
| 4054 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4055 | } |
| 4056 | } |
| 4057 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4058 | void LocationsBuilderX86_64::VisitMin(HMin* min) { |
| 4059 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4060 | } |
| 4061 | |
| 4062 | void InstructionCodeGeneratorX86_64::VisitMin(HMin* min) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4063 | GenerateMinMax(min, /*is_min*/ true); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | void LocationsBuilderX86_64::VisitMax(HMax* max) { |
| 4067 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4068 | } |
| 4069 | |
| 4070 | void InstructionCodeGeneratorX86_64::VisitMax(HMax* max) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4071 | GenerateMinMax(max, /*is_min*/ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4072 | } |
| 4073 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4074 | void LocationsBuilderX86_64::VisitAbs(HAbs* abs) { |
| 4075 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4076 | switch (abs->GetResultType()) { |
| 4077 | case DataType::Type::kInt32: |
| 4078 | case DataType::Type::kInt64: |
| 4079 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4080 | locations->SetOut(Location::SameAsFirstInput()); |
| 4081 | locations->AddTemp(Location::RequiresRegister()); |
| 4082 | break; |
| 4083 | case DataType::Type::kFloat32: |
| 4084 | case DataType::Type::kFloat64: |
| 4085 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4086 | locations->SetOut(Location::SameAsFirstInput()); |
| 4087 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4088 | break; |
| 4089 | default: |
| 4090 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4091 | } |
| 4092 | } |
| 4093 | |
| 4094 | void InstructionCodeGeneratorX86_64::VisitAbs(HAbs* abs) { |
| 4095 | LocationSummary* locations = abs->GetLocations(); |
| 4096 | switch (abs->GetResultType()) { |
| 4097 | case DataType::Type::kInt32: { |
| 4098 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4099 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4100 | // Create mask. |
| 4101 | __ movl(mask, out); |
| 4102 | __ sarl(mask, Immediate(31)); |
| 4103 | // Add mask. |
| 4104 | __ addl(out, mask); |
| 4105 | __ xorl(out, mask); |
| 4106 | break; |
| 4107 | } |
| 4108 | case DataType::Type::kInt64: { |
| 4109 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4110 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4111 | // Create mask. |
| 4112 | __ movq(mask, out); |
| 4113 | __ sarq(mask, Immediate(63)); |
| 4114 | // Add mask. |
| 4115 | __ addq(out, mask); |
| 4116 | __ xorq(out, mask); |
| 4117 | break; |
| 4118 | } |
| 4119 | case DataType::Type::kFloat32: { |
| 4120 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4121 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4122 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x7FFFFFFF))); |
| 4123 | __ andps(out, mask); |
| 4124 | break; |
| 4125 | } |
| 4126 | case DataType::Type::kFloat64: { |
| 4127 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4128 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4129 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x7FFFFFFFFFFFFFFF))); |
| 4130 | __ andpd(out, mask); |
| 4131 | break; |
| 4132 | } |
| 4133 | default: |
| 4134 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4135 | } |
| 4136 | } |
| 4137 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4138 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4139 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4140 | locations->SetInAt(0, Location::Any()); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4144 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4145 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86_64(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4146 | codegen_->AddSlowPath(slow_path); |
| 4147 | |
| 4148 | LocationSummary* locations = instruction->GetLocations(); |
| 4149 | Location value = locations->InAt(0); |
| 4150 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4151 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4152 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4153 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4154 | case DataType::Type::kInt8: |
| 4155 | case DataType::Type::kUint16: |
| 4156 | case DataType::Type::kInt16: |
| 4157 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4158 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4159 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4160 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4161 | } else if (value.IsStackSlot()) { |
| 4162 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4163 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4164 | } else { |
| 4165 | DCHECK(value.IsConstant()) << value; |
| 4166 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4167 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4168 | } |
| 4169 | } |
| 4170 | break; |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4171 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4172 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4173 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4174 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4175 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4176 | } else if (value.IsDoubleStackSlot()) { |
| 4177 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4178 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4179 | } else { |
| 4180 | DCHECK(value.IsConstant()) << value; |
| 4181 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4182 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4183 | } |
| 4184 | } |
| 4185 | break; |
| 4186 | } |
| 4187 | default: |
| 4188 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4189 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4190 | } |
| 4191 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4192 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 4193 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4194 | |
| 4195 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4196 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4197 | |
| 4198 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4199 | case DataType::Type::kInt32: |
| 4200 | case DataType::Type::kInt64: { |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4201 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4202 | // The shift count needs to be in CL. |
| 4203 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 4204 | locations->SetOut(Location::SameAsFirstInput()); |
| 4205 | break; |
| 4206 | } |
| 4207 | default: |
| 4208 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4209 | } |
| 4210 | } |
| 4211 | |
| 4212 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 4213 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4214 | |
| 4215 | LocationSummary* locations = op->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4216 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4217 | Location second = locations->InAt(1); |
| 4218 | |
| 4219 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4220 | case DataType::Type::kInt32: { |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4221 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4222 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4223 | if (op->IsShl()) { |
| 4224 | __ shll(first_reg, second_reg); |
| 4225 | } else if (op->IsShr()) { |
| 4226 | __ sarl(first_reg, second_reg); |
| 4227 | } else { |
| 4228 | __ shrl(first_reg, second_reg); |
| 4229 | } |
| 4230 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4231 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4232 | if (op->IsShl()) { |
| 4233 | __ shll(first_reg, imm); |
| 4234 | } else if (op->IsShr()) { |
| 4235 | __ sarl(first_reg, imm); |
| 4236 | } else { |
| 4237 | __ shrl(first_reg, imm); |
| 4238 | } |
| 4239 | } |
| 4240 | break; |
| 4241 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4242 | case DataType::Type::kInt64: { |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4243 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4244 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4245 | if (op->IsShl()) { |
| 4246 | __ shlq(first_reg, second_reg); |
| 4247 | } else if (op->IsShr()) { |
| 4248 | __ sarq(first_reg, second_reg); |
| 4249 | } else { |
| 4250 | __ shrq(first_reg, second_reg); |
| 4251 | } |
| 4252 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4253 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4254 | if (op->IsShl()) { |
| 4255 | __ shlq(first_reg, imm); |
| 4256 | } else if (op->IsShr()) { |
| 4257 | __ sarq(first_reg, imm); |
| 4258 | } else { |
| 4259 | __ shrq(first_reg, imm); |
| 4260 | } |
| 4261 | } |
| 4262 | break; |
| 4263 | } |
| 4264 | default: |
| 4265 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4266 | UNREACHABLE(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4267 | } |
| 4268 | } |
| 4269 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4270 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 4271 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4272 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4273 | |
| 4274 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4275 | case DataType::Type::kInt32: |
| 4276 | case DataType::Type::kInt64: { |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4277 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4278 | // The shift count needs to be in CL (unless it is a constant). |
| 4279 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 4280 | locations->SetOut(Location::SameAsFirstInput()); |
| 4281 | break; |
| 4282 | } |
| 4283 | default: |
| 4284 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4285 | UNREACHABLE(); |
| 4286 | } |
| 4287 | } |
| 4288 | |
| 4289 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4290 | LocationSummary* locations = ror->GetLocations(); |
| 4291 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4292 | Location second = locations->InAt(1); |
| 4293 | |
| 4294 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4295 | case DataType::Type::kInt32: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4296 | if (second.IsRegister()) { |
| 4297 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4298 | __ rorl(first_reg, second_reg); |
| 4299 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4300 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4301 | __ rorl(first_reg, imm); |
| 4302 | } |
| 4303 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4304 | case DataType::Type::kInt64: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4305 | if (second.IsRegister()) { |
| 4306 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4307 | __ rorq(first_reg, second_reg); |
| 4308 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4309 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4310 | __ rorq(first_reg, imm); |
| 4311 | } |
| 4312 | break; |
| 4313 | default: |
| 4314 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4315 | UNREACHABLE(); |
| 4316 | } |
| 4317 | } |
| 4318 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4319 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4320 | HandleShift(shl); |
| 4321 | } |
| 4322 | |
| 4323 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4324 | HandleShift(shl); |
| 4325 | } |
| 4326 | |
| 4327 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4328 | HandleShift(shr); |
| 4329 | } |
| 4330 | |
| 4331 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4332 | HandleShift(shr); |
| 4333 | } |
| 4334 | |
| 4335 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4336 | HandleShift(ushr); |
| 4337 | } |
| 4338 | |
| 4339 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4340 | HandleShift(ushr); |
| 4341 | } |
| 4342 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4343 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4344 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4345 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4346 | InvokeRuntimeCallingConvention calling_convention; |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4347 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4348 | locations->SetOut(Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4352 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4353 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4354 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4355 | } |
| 4356 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4357 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4358 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4359 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4360 | InvokeRuntimeCallingConvention calling_convention; |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4361 | locations->SetOut(Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4362 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4363 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4364 | } |
| 4365 | |
| 4366 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4367 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4368 | // of poisoning the reference. |
| Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4369 | QuickEntrypointEnum entrypoint = |
| 4370 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4371 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4372 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4373 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4374 | } |
| 4375 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4376 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4377 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4378 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4379 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4380 | if (location.IsStackSlot()) { |
| 4381 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4382 | } else if (location.IsDoubleStackSlot()) { |
| 4383 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4384 | } |
| 4385 | locations->SetOut(location); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4386 | } |
| 4387 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4388 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4389 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4390 | // Nothing to do, the parameter is already at its location. |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4391 | } |
| 4392 | |
| 4393 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4394 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4395 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4396 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4397 | } |
| 4398 | |
| 4399 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4400 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4401 | // Nothing to do, the method is already at its location. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4402 | } |
| 4403 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4404 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4405 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4406 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4407 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4408 | locations->SetOut(Location::RequiresRegister()); |
| 4409 | } |
| 4410 | |
| 4411 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4412 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4413 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4414 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4415 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4416 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4417 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4418 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4419 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4420 | instruction->GetIndex(), kX86_64PointerSize)); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4421 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4422 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4423 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4424 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4425 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4426 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4427 | } |
| 4428 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4429 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4430 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4431 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4432 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4433 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4434 | } |
| 4435 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4436 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4437 | LocationSummary* locations = not_->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4438 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4439 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4440 | Location out = locations->Out(); |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4441 | switch (not_->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4442 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4443 | __ notl(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4444 | break; |
| 4445 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4446 | case DataType::Type::kInt64: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4447 | __ notq(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4448 | break; |
| 4449 | |
| 4450 | default: |
| 4451 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4452 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4453 | } |
| 4454 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4455 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4456 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4457 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4458 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4459 | locations->SetOut(Location::SameAsFirstInput()); |
| 4460 | } |
| 4461 | |
| 4462 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4463 | LocationSummary* locations = bool_not->GetLocations(); |
| 4464 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4465 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4466 | Location out = locations->Out(); |
| 4467 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4468 | } |
| 4469 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4470 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4471 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4472 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4473 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4474 | locations->SetInAt(i, Location::Any()); |
| 4475 | } |
| 4476 | locations->SetOut(Location::Any()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4477 | } |
| 4478 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4479 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4480 | LOG(FATAL) << "Unimplemented"; |
| 4481 | } |
| 4482 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4483 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4484 | /* |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4485 | * According to the JSR-133 Cookbook, for x86-64 only StoreLoad/AnyAny barriers need memory fence. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4486 | * 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] | 4487 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4488 | */ |
| 4489 | switch (kind) { |
| 4490 | case MemBarrierKind::kAnyAny: { |
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4491 | MemoryFence(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4492 | break; |
| 4493 | } |
| 4494 | case MemBarrierKind::kAnyStore: |
| 4495 | case MemBarrierKind::kLoadAny: |
| 4496 | case MemBarrierKind::kStoreStore: { |
| 4497 | // nop |
| 4498 | break; |
| 4499 | } |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4500 | case MemBarrierKind::kNTStoreStore: |
| 4501 | // Non-Temporal Store/Store needs an explicit fence. |
| 4502 | MemoryFence(/* non-temporal */ true); |
| 4503 | break; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4504 | } |
| 4505 | } |
| 4506 | |
| 4507 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4508 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4509 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4510 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4511 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4512 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4513 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4514 | object_field_get_with_read_barrier |
| 4515 | ? LocationSummary::kCallOnSlowPath |
| 4516 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4517 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4518 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4519 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4520 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4521 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4522 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4523 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4524 | // The output overlaps for an object field get when read barriers |
| 4525 | // are enabled: we do not want the move to overwrite the object's |
| 4526 | // location, as we need it to emit the read barrier. |
| 4527 | locations->SetOut( |
| 4528 | Location::RequiresRegister(), |
| 4529 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4530 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4531 | } |
| 4532 | |
| 4533 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4534 | const FieldInfo& field_info) { |
| 4535 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4536 | |
| 4537 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4538 | Location base_loc = locations->InAt(0); |
| 4539 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4540 | Location out = locations->Out(); |
| 4541 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4542 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4543 | DataType::Type load_type = instruction->GetType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4544 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4545 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4546 | switch (load_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4547 | case DataType::Type::kBool: |
| 4548 | case DataType::Type::kUint8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4549 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4550 | break; |
| 4551 | } |
| 4552 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4553 | case DataType::Type::kInt8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4554 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4555 | break; |
| 4556 | } |
| 4557 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4558 | case DataType::Type::kUint16: { |
| 4559 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4560 | break; |
| 4561 | } |
| 4562 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4563 | case DataType::Type::kInt16: { |
| 4564 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4565 | break; |
| 4566 | } |
| 4567 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4568 | case DataType::Type::kInt32: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4569 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4570 | break; |
| 4571 | } |
| 4572 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4573 | case DataType::Type::kReference: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4574 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4575 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4576 | // Note that a potential implicit null check is handled in this |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4577 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4578 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4579 | instruction, out, base, offset, /* needs_null_check */ true); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4580 | if (is_volatile) { |
| 4581 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4582 | } |
| 4583 | } else { |
| 4584 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4585 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4586 | if (is_volatile) { |
| 4587 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4588 | } |
| 4589 | // If read barriers are enabled, emit read barriers other than |
| 4590 | // Baker's using a slow path (and also unpoison the loaded |
| 4591 | // reference, if heap poisoning is enabled). |
| 4592 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4593 | } |
| 4594 | break; |
| 4595 | } |
| 4596 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4597 | case DataType::Type::kInt64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4598 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4599 | break; |
| 4600 | } |
| 4601 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4602 | case DataType::Type::kFloat32: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4603 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4604 | break; |
| 4605 | } |
| 4606 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4607 | case DataType::Type::kFloat64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4608 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4609 | break; |
| 4610 | } |
| 4611 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4612 | case DataType::Type::kUint32: |
| 4613 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4614 | case DataType::Type::kVoid: |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4615 | LOG(FATAL) << "Unreachable type " << load_type; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4616 | UNREACHABLE(); |
| 4617 | } |
| 4618 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4619 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4620 | // Potential implicit null checks, in the case of reference |
| 4621 | // fields, are handled in the previous switch statement. |
| 4622 | } else { |
| 4623 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4624 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4625 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4626 | if (is_volatile) { |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4627 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4628 | // Memory barriers, in the case of references, are also handled |
| 4629 | // in the previous switch statement. |
| 4630 | } else { |
| 4631 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4632 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4633 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4634 | } |
| 4635 | |
| 4636 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4637 | const FieldInfo& field_info) { |
| 4638 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4639 | |
| 4640 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4641 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4642 | DataType::Type field_type = field_info.GetFieldType(); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4643 | bool is_volatile = field_info.IsVolatile(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4644 | bool needs_write_barrier = |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4645 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4646 | |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4647 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4648 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4649 | if (is_volatile) { |
| 4650 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4651 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4652 | } else { |
| 4653 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4654 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4655 | } else { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4656 | if (is_volatile) { |
| 4657 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4658 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4659 | } else { |
| 4660 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4661 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4662 | } |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4663 | if (needs_write_barrier) { |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4664 | // Temporary registers for the write barrier. |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4665 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4666 | locations->AddTemp(Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4667 | } else if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4668 | // Temporary register for the reference poisoning. |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4669 | locations->AddTemp(Location::RequiresRegister()); |
| 4670 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4671 | } |
| 4672 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4673 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4674 | const FieldInfo& field_info, |
| 4675 | bool value_can_be_null) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4676 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4677 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4678 | LocationSummary* locations = instruction->GetLocations(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4679 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4680 | Location value = locations->InAt(1); |
| 4681 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4682 | DataType::Type field_type = field_info.GetFieldType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4683 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4684 | |
| 4685 | if (is_volatile) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4686 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4687 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4688 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4689 | bool maybe_record_implicit_null_check_done = false; |
| 4690 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4691 | switch (field_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4692 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4693 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4694 | case DataType::Type::kInt8: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4695 | if (value.IsConstant()) { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4696 | __ movb(Address(base, offset), |
| 4697 | Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4698 | } else { |
| 4699 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4700 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4701 | break; |
| 4702 | } |
| 4703 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4704 | case DataType::Type::kUint16: |
| 4705 | case DataType::Type::kInt16: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4706 | if (value.IsConstant()) { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4707 | __ movw(Address(base, offset), |
| 4708 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4709 | } else { |
| 4710 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4711 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4712 | break; |
| 4713 | } |
| 4714 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4715 | case DataType::Type::kInt32: |
| 4716 | case DataType::Type::kReference: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4717 | if (value.IsConstant()) { |
| 4718 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4719 | // `field_type == DataType::Type::kReference` implies `v == 0`. |
| 4720 | DCHECK((field_type != DataType::Type::kReference) || (v == 0)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4721 | // Note: if heap poisoning is enabled, no need to poison |
| 4722 | // (negate) `v` if it is a reference, as it would be null. |
| Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4723 | __ movl(Address(base, offset), Immediate(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4724 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4725 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4726 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4727 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4728 | __ PoisonHeapReference(temp); |
| 4729 | __ movl(Address(base, offset), temp); |
| 4730 | } else { |
| 4731 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4732 | } |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4733 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4734 | break; |
| 4735 | } |
| 4736 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4737 | case DataType::Type::kInt64: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4738 | if (value.IsConstant()) { |
| 4739 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4740 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4741 | Address(base, offset + sizeof(int32_t)), |
| 4742 | v, |
| 4743 | instruction); |
| 4744 | maybe_record_implicit_null_check_done = true; |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4745 | } else { |
| 4746 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4747 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4748 | break; |
| 4749 | } |
| 4750 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4751 | case DataType::Type::kFloat32: { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4752 | if (value.IsConstant()) { |
| 4753 | int32_t v = |
| 4754 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4755 | __ movl(Address(base, offset), Immediate(v)); |
| 4756 | } else { |
| 4757 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4758 | } |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4759 | break; |
| 4760 | } |
| 4761 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4762 | case DataType::Type::kFloat64: { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4763 | if (value.IsConstant()) { |
| 4764 | int64_t v = |
| 4765 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4766 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4767 | Address(base, offset + sizeof(int32_t)), |
| 4768 | v, |
| 4769 | instruction); |
| 4770 | maybe_record_implicit_null_check_done = true; |
| 4771 | } else { |
| 4772 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4773 | } |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4774 | break; |
| 4775 | } |
| 4776 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4777 | case DataType::Type::kUint32: |
| 4778 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4779 | case DataType::Type::kVoid: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4780 | LOG(FATAL) << "Unreachable type " << field_type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4781 | UNREACHABLE(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4782 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4783 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4784 | if (!maybe_record_implicit_null_check_done) { |
| 4785 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4786 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4787 | |
| 4788 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4789 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4790 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4791 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4792 | } |
| 4793 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4794 | if (is_volatile) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4795 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4796 | } |
| 4797 | } |
| 4798 | |
| 4799 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4800 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4801 | } |
| 4802 | |
| 4803 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4804 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4805 | } |
| 4806 | |
| 4807 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4808 | HandleFieldGet(instruction); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4809 | } |
| 4810 | |
| 4811 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4812 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4813 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4814 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4815 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4816 | HandleFieldGet(instruction); |
| 4817 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4818 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4819 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4820 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4821 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4822 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4823 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4824 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4825 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4826 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4827 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4828 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4829 | } |
| 4830 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4831 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4832 | HUnresolvedInstanceFieldGet* instruction) { |
| 4833 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4834 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4835 | instruction, instruction->GetFieldType(), calling_convention); |
| 4836 | } |
| 4837 | |
| 4838 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4839 | HUnresolvedInstanceFieldGet* instruction) { |
| 4840 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4841 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4842 | instruction->GetFieldType(), |
| 4843 | instruction->GetFieldIndex(), |
| 4844 | instruction->GetDexPc(), |
| 4845 | calling_convention); |
| 4846 | } |
| 4847 | |
| 4848 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4849 | HUnresolvedInstanceFieldSet* instruction) { |
| 4850 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4851 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4852 | instruction, instruction->GetFieldType(), calling_convention); |
| 4853 | } |
| 4854 | |
| 4855 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4856 | HUnresolvedInstanceFieldSet* instruction) { |
| 4857 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4858 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4859 | instruction->GetFieldType(), |
| 4860 | instruction->GetFieldIndex(), |
| 4861 | instruction->GetDexPc(), |
| 4862 | calling_convention); |
| 4863 | } |
| 4864 | |
| 4865 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4866 | HUnresolvedStaticFieldGet* instruction) { |
| 4867 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4868 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4869 | instruction, instruction->GetFieldType(), calling_convention); |
| 4870 | } |
| 4871 | |
| 4872 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4873 | HUnresolvedStaticFieldGet* instruction) { |
| 4874 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4875 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4876 | instruction->GetFieldType(), |
| 4877 | instruction->GetFieldIndex(), |
| 4878 | instruction->GetDexPc(), |
| 4879 | calling_convention); |
| 4880 | } |
| 4881 | |
| 4882 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4883 | HUnresolvedStaticFieldSet* instruction) { |
| 4884 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4885 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4886 | instruction, instruction->GetFieldType(), calling_convention); |
| 4887 | } |
| 4888 | |
| 4889 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4890 | HUnresolvedStaticFieldSet* instruction) { |
| 4891 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4892 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4893 | instruction->GetFieldType(), |
| 4894 | instruction->GetFieldIndex(), |
| 4895 | instruction->GetDexPc(), |
| 4896 | calling_convention); |
| 4897 | } |
| 4898 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4899 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4900 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4901 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4902 | ? Location::RequiresRegister() |
| 4903 | : Location::Any(); |
| 4904 | locations->SetInAt(0, loc); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4905 | } |
| 4906 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4907 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4908 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4909 | return; |
| 4910 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4911 | LocationSummary* locations = instruction->GetLocations(); |
| 4912 | Location obj = locations->InAt(0); |
| 4913 | |
| 4914 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4915 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4918 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4919 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86_64(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4920 | AddSlowPath(slow_path); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4921 | |
| 4922 | LocationSummary* locations = instruction->GetLocations(); |
| 4923 | Location obj = locations->InAt(0); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4924 | |
| 4925 | if (obj.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4926 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4927 | } else if (obj.IsStackSlot()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4928 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4929 | } else { |
| 4930 | DCHECK(obj.IsConstant()) << obj; |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4931 | DCHECK(obj.GetConstant()->IsNullConstant()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4932 | __ jmp(slow_path->GetEntryLabel()); |
| 4933 | return; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4934 | } |
| 4935 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4936 | } |
| 4937 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4938 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4939 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4940 | } |
| 4941 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4942 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4943 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4944 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4945 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4946 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4947 | object_array_get_with_read_barrier |
| 4948 | ? LocationSummary::kCallOnSlowPath |
| 4949 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4950 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4951 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4952 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4953 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4954 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4955 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4956 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4957 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4958 | // The output overlaps for an object array get when read barriers |
| 4959 | // are enabled: we do not want the move to overwrite the array's |
| 4960 | // location, as we need it to emit the read barrier. |
| 4961 | locations->SetOut( |
| 4962 | Location::RequiresRegister(), |
| 4963 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4964 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4965 | } |
| 4966 | |
| 4967 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4968 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4969 | Location obj_loc = locations->InAt(0); |
| 4970 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4971 | Location index = locations->InAt(1); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4972 | Location out_loc = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4973 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4974 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4975 | DataType::Type type = instruction->GetType(); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4976 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4977 | case DataType::Type::kBool: |
| 4978 | case DataType::Type::kUint8: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4979 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4980 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4981 | break; |
| 4982 | } |
| 4983 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4984 | case DataType::Type::kInt8: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4985 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4986 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4987 | break; |
| 4988 | } |
| 4989 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4990 | case DataType::Type::kUint16: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4991 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4992 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 4993 | // Branch cases into compressed and uncompressed for each index's type. |
| 4994 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 4995 | NearLabel done, not_compressed; |
| Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 4996 | __ testb(Address(obj, count_offset), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 4997 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 4998 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 4999 | "Expecting 0=compressed, 1=uncompressed"); |
| 5000 | __ j(kNotZero, ¬_compressed); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5001 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5002 | __ jmp(&done); |
| 5003 | __ Bind(¬_compressed); |
| 5004 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5005 | __ Bind(&done); |
| 5006 | } else { |
| 5007 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5008 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5009 | break; |
| 5010 | } |
| 5011 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5012 | case DataType::Type::kInt16: { |
| 5013 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 5014 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5015 | break; |
| 5016 | } |
| 5017 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5018 | case DataType::Type::kInt32: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5019 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5020 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5021 | break; |
| 5022 | } |
| 5023 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5024 | case DataType::Type::kReference: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5025 | static_assert( |
| 5026 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5027 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5028 | // /* HeapReference<Object> */ out = |
| 5029 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5030 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5031 | // Note that a potential implicit null check is handled in this |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5032 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5033 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5034 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5035 | } else { |
| 5036 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5037 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5038 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5039 | // If read barriers are enabled, emit read barriers other than |
| 5040 | // Baker's using a slow path (and also unpoison the loaded |
| 5041 | // reference, if heap poisoning is enabled). |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5042 | if (index.IsConstant()) { |
| 5043 | uint32_t offset = |
| 5044 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5045 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5046 | } else { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5047 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5048 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5049 | } |
| 5050 | } |
| 5051 | break; |
| 5052 | } |
| 5053 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5054 | case DataType::Type::kInt64: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5055 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5056 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5057 | break; |
| 5058 | } |
| 5059 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5060 | case DataType::Type::kFloat32: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5061 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5062 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5063 | break; |
| 5064 | } |
| 5065 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5066 | case DataType::Type::kFloat64: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5067 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5068 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5069 | break; |
| 5070 | } |
| 5071 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5072 | case DataType::Type::kUint32: |
| 5073 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5074 | case DataType::Type::kVoid: |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5075 | LOG(FATAL) << "Unreachable type " << type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5076 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5077 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5078 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5079 | if (type == DataType::Type::kReference) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5080 | // Potential implicit null checks, in the case of reference |
| 5081 | // arrays, are handled in the previous switch statement. |
| 5082 | } else { |
| 5083 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5084 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5085 | } |
| 5086 | |
| 5087 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5088 | DataType::Type value_type = instruction->GetComponentType(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5089 | |
| 5090 | bool needs_write_barrier = |
| 5091 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5092 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5093 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5094 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5095 | instruction, |
| Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5096 | may_need_runtime_call_for_type_check ? |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5097 | LocationSummary::kCallOnSlowPath : |
| 5098 | LocationSummary::kNoCall); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5099 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5100 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5101 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5102 | if (DataType::IsFloatingPointType(value_type)) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5103 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5104 | } else { |
| 5105 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5106 | } |
| 5107 | |
| 5108 | if (needs_write_barrier) { |
| 5109 | // Temporary registers for the write barrier. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5110 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5111 | locations->AddTemp(Location::RequiresRegister()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5112 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 5116 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5117 | Location array_loc = locations->InAt(0); |
| 5118 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5119 | Location index = locations->InAt(1); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5120 | Location value = locations->InAt(2); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5121 | DataType::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5122 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5123 | bool needs_write_barrier = |
| 5124 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5125 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5126 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5127 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5128 | |
| 5129 | switch (value_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5130 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5131 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5132 | case DataType::Type::kInt8: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5133 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5134 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5135 | if (value.IsRegister()) { |
| 5136 | __ movb(address, value.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5137 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5138 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5139 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5140 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5141 | break; |
| 5142 | } |
| 5143 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5144 | case DataType::Type::kUint16: |
| 5145 | case DataType::Type::kInt16: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5146 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5147 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5148 | if (value.IsRegister()) { |
| 5149 | __ movw(address, value.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5150 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5151 | DCHECK(value.IsConstant()) << value; |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5152 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5153 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5154 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5155 | break; |
| 5156 | } |
| 5157 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5158 | case DataType::Type::kReference: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5159 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5160 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5161 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5162 | if (!value.IsRegister()) { |
| 5163 | // Just setting null. |
| 5164 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5165 | DCHECK(value.IsConstant()) << value; |
| 5166 | __ movl(address, Immediate(0)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5167 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5168 | DCHECK(!needs_write_barrier); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5169 | DCHECK(!may_need_runtime_call_for_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5170 | break; |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5171 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5172 | |
| 5173 | DCHECK(needs_write_barrier); |
| 5174 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5175 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5176 | // short when Baker read barriers are enabled. |
| 5177 | Label done; |
| 5178 | NearLabel not_null, do_put; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5179 | SlowPathCode* slow_path = nullptr; |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5180 | Location temp_loc = locations->GetTemp(0); |
| 5181 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5182 | if (may_need_runtime_call_for_type_check) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5183 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86_64(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5184 | codegen_->AddSlowPath(slow_path); |
| 5185 | if (instruction->GetValueCanBeNull()) { |
| 5186 | __ testl(register_value, register_value); |
| 5187 | __ j(kNotEqual, ¬_null); |
| 5188 | __ movl(address, Immediate(0)); |
| 5189 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5190 | __ jmp(&done); |
| 5191 | __ Bind(¬_null); |
| 5192 | } |
| 5193 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5194 | // Note that when Baker read barriers are enabled, the type |
| 5195 | // checks are performed without read barriers. This is fine, |
| 5196 | // even in the case where a class object is in the from-space |
| 5197 | // after the flip, as a comparison involving such a type would |
| 5198 | // not produce a false positive; it may of course produce a |
| 5199 | // false negative, in which case we would take the ArraySet |
| 5200 | // slow path. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5201 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5202 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5203 | __ movl(temp, Address(array, class_offset)); |
| 5204 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5205 | __ MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5206 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5207 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5208 | __ movl(temp, Address(temp, component_offset)); |
| 5209 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5210 | // nor the object reference in `register_value->klass`, as |
| 5211 | // we are comparing two poisoned references. |
| 5212 | __ cmpl(temp, Address(register_value, class_offset)); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5213 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5214 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5215 | __ j(kEqual, &do_put); |
| 5216 | // If heap poisoning is enabled, the `temp` reference has |
| 5217 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5218 | __ MaybeUnpoisonHeapReference(temp); |
| 5219 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5220 | // If heap poisoning is enabled, no need to unpoison the |
| 5221 | // heap reference loaded below, as it is only used for a |
| 5222 | // comparison with null. |
| 5223 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5224 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5225 | __ Bind(&do_put); |
| 5226 | } else { |
| 5227 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5228 | } |
| 5229 | } |
| 5230 | |
| 5231 | if (kPoisonHeapReferences) { |
| 5232 | __ movl(temp, register_value); |
| 5233 | __ PoisonHeapReference(temp); |
| 5234 | __ movl(address, temp); |
| 5235 | } else { |
| 5236 | __ movl(address, register_value); |
| 5237 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5238 | if (!may_need_runtime_call_for_type_check) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5239 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5240 | } |
| 5241 | |
| 5242 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 5243 | codegen_->MarkGCCard( |
| 5244 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 5245 | __ Bind(&done); |
| 5246 | |
| 5247 | if (slow_path != nullptr) { |
| 5248 | __ Bind(slow_path->GetExitLabel()); |
| 5249 | } |
| 5250 | |
| 5251 | break; |
| 5252 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5253 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5254 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5255 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5256 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5257 | if (value.IsRegister()) { |
| 5258 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 5259 | } else { |
| 5260 | DCHECK(value.IsConstant()) << value; |
| 5261 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5262 | __ movl(address, Immediate(v)); |
| 5263 | } |
| 5264 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5265 | break; |
| 5266 | } |
| 5267 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5268 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5269 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5270 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5271 | if (value.IsRegister()) { |
| 5272 | __ movq(address, value.AsRegister<CpuRegister>()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5273 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5274 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5275 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5276 | Address address_high = |
| 5277 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5278 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5279 | } |
| 5280 | break; |
| 5281 | } |
| 5282 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5283 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5284 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5285 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5286 | if (value.IsFpuRegister()) { |
| 5287 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5288 | } else { |
| 5289 | DCHECK(value.IsConstant()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5290 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5291 | __ movl(address, Immediate(v)); |
| 5292 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5293 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5294 | break; |
| 5295 | } |
| 5296 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5297 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5298 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5299 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5300 | if (value.IsFpuRegister()) { |
| 5301 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5302 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5303 | } else { |
| 5304 | int64_t v = |
| 5305 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5306 | Address address_high = |
| 5307 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5308 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5309 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5310 | break; |
| 5311 | } |
| 5312 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5313 | case DataType::Type::kUint32: |
| 5314 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5315 | case DataType::Type::kVoid: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5316 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5317 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5318 | } |
| 5319 | } |
| 5320 | |
| 5321 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5322 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5323 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5324 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5325 | if (!instruction->IsEmittedAtUseSite()) { |
| 5326 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5327 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5331 | if (instruction->IsEmittedAtUseSite()) { |
| 5332 | return; |
| 5333 | } |
| 5334 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5335 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5336 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5337 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5338 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5339 | __ movl(out, Address(obj, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5340 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5341 | // Mask out most significant bit in case the array is String's array of char. |
| 5342 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5343 | __ shrl(out, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5344 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5348 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5349 | InvokeRuntimeCallingConvention calling_convention; |
| 5350 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5351 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5352 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5353 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5354 | HInstruction* length = instruction->InputAt(1); |
| 5355 | if (!length->IsEmittedAtUseSite()) { |
| 5356 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5357 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5361 | LocationSummary* locations = instruction->GetLocations(); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5362 | Location index_loc = locations->InAt(0); |
| 5363 | Location length_loc = locations->InAt(1); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5364 | SlowPathCode* slow_path = |
| 5365 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86_64(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5366 | |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5367 | if (length_loc.IsConstant()) { |
| 5368 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5369 | if (index_loc.IsConstant()) { |
| 5370 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5371 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5372 | if (index < 0 || index >= length) { |
| 5373 | codegen_->AddSlowPath(slow_path); |
| 5374 | __ jmp(slow_path->GetEntryLabel()); |
| 5375 | } else { |
| 5376 | // Some optimization after BCE may have generated this, and we should not |
| 5377 | // generate a bounds check if it is a valid range. |
| 5378 | } |
| 5379 | return; |
| 5380 | } |
| 5381 | |
| 5382 | // We have to reverse the jump condition because the length is the constant. |
| 5383 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5384 | __ cmpl(index_reg, Immediate(length)); |
| 5385 | codegen_->AddSlowPath(slow_path); |
| 5386 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5387 | } else { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5388 | HInstruction* array_length = instruction->InputAt(1); |
| 5389 | if (array_length->IsEmittedAtUseSite()) { |
| 5390 | // Address the length field in the array. |
| 5391 | DCHECK(array_length->IsArrayLength()); |
| 5392 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5393 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5394 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5395 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5396 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5397 | // the string compression flag) with the in-memory length and avoid the temporary. |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5398 | CpuRegister length_reg = CpuRegister(TMP); |
| 5399 | __ movl(length_reg, array_len); |
| 5400 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5401 | __ shrl(length_reg, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5402 | codegen_->GenerateIntCompare(length_reg, index_loc); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5403 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5404 | // Checking the bound for general case: |
| 5405 | // Array of char or String's array when the compression feature off. |
| 5406 | if (index_loc.IsConstant()) { |
| 5407 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5408 | __ cmpl(array_len, Immediate(value)); |
| 5409 | } else { |
| 5410 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5411 | } |
| 5412 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5413 | } |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5414 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5415 | codegen_->GenerateIntCompare(length_loc, index_loc); |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5416 | } |
| 5417 | codegen_->AddSlowPath(slow_path); |
| 5418 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5419 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5420 | } |
| 5421 | |
| 5422 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5423 | CpuRegister card, |
| 5424 | CpuRegister object, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5425 | CpuRegister value, |
| 5426 | bool value_can_be_null) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5427 | NearLabel is_null; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5428 | if (value_can_be_null) { |
| 5429 | __ testl(value, value); |
| 5430 | __ j(kEqual, &is_null); |
| 5431 | } |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5432 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5433 | /* no_rip */ true)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5434 | __ movq(temp, object); |
| 5435 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5436 | __ movb(Address(temp, card, TIMES_1, 0), card); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5437 | if (value_can_be_null) { |
| 5438 | __ Bind(&is_null); |
| 5439 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5440 | } |
| 5441 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5442 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5443 | LOG(FATAL) << "Unimplemented"; |
| 5444 | } |
| 5445 | |
| 5446 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5447 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5448 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5449 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5450 | // The back edge will generate the suspend check. |
| 5451 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5452 | } |
| 5453 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5454 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5455 | } |
| 5456 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5457 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5458 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5459 | instruction, LocationSummary::kCallOnSlowPath); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5460 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5461 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5462 | // registers in full width (since the runtime only saves/restores lower part). |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5463 | locations->SetCustomSlowPathCallerSaves( |
| 5464 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5465 | } |
| 5466 | |
| 5467 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5468 | HBasicBlock* block = instruction->GetBlock(); |
| 5469 | if (block->GetLoopInformation() != nullptr) { |
| 5470 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5471 | // The back edge will generate the suspend check. |
| 5472 | return; |
| 5473 | } |
| 5474 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5475 | // The goto will generate the suspend check. |
| 5476 | return; |
| 5477 | } |
| 5478 | GenerateSuspendCheck(instruction, nullptr); |
| 5479 | } |
| 5480 | |
| 5481 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5482 | HBasicBlock* successor) { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5483 | SuspendCheckSlowPathX86_64* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5484 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5485 | if (slow_path == nullptr) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5486 | slow_path = |
| 5487 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86_64(instruction, successor); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5488 | instruction->SetSlowPath(slow_path); |
| 5489 | codegen_->AddSlowPath(slow_path); |
| 5490 | if (successor != nullptr) { |
| 5491 | DCHECK(successor->IsLoopHeader()); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5492 | } |
| 5493 | } else { |
| 5494 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5495 | } |
| 5496 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5497 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5498 | /* no_rip */ true), |
| 5499 | Immediate(0)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5500 | if (successor == nullptr) { |
| 5501 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5502 | __ Bind(slow_path->GetReturnLabel()); |
| 5503 | } else { |
| 5504 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5505 | __ jmp(slow_path->GetEntryLabel()); |
| 5506 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5507 | } |
| 5508 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5509 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5510 | return codegen_->GetAssembler(); |
| 5511 | } |
| 5512 | |
| 5513 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5514 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5515 | Location source = move->GetSource(); |
| 5516 | Location destination = move->GetDestination(); |
| 5517 | |
| 5518 | if (source.IsRegister()) { |
| 5519 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5520 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5521 | } else if (destination.IsStackSlot()) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5522 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5523 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5524 | } else { |
| 5525 | DCHECK(destination.IsDoubleStackSlot()); |
| 5526 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5527 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5528 | } |
| 5529 | } else if (source.IsStackSlot()) { |
| 5530 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5531 | __ movl(destination.AsRegister<CpuRegister>(), |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5532 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5533 | } else if (destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5534 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5535 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5536 | } else { |
| 5537 | DCHECK(destination.IsStackSlot()); |
| 5538 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5539 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5540 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5541 | } else if (source.IsDoubleStackSlot()) { |
| 5542 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5543 | __ movq(destination.AsRegister<CpuRegister>(), |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5544 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5545 | } else if (destination.IsFpuRegister()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5546 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5547 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5548 | } else { |
| Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5549 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5550 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5551 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5552 | } |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5553 | } else if (source.IsSIMDStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5554 | if (destination.IsFpuRegister()) { |
| 5555 | __ movups(destination.AsFpuRegister<XmmRegister>(), |
| 5556 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5557 | } else { |
| 5558 | DCHECK(destination.IsSIMDStackSlot()); |
| 5559 | size_t high = kX86_64WordSize; |
| 5560 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5561 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5562 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex() + high)); |
| 5563 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex() + high), CpuRegister(TMP)); |
| 5564 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5565 | } else if (source.IsConstant()) { |
| 5566 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5567 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5568 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5569 | if (destination.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5570 | if (value == 0) { |
| 5571 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5572 | } else { |
| 5573 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5574 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5575 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5576 | DCHECK(destination.IsStackSlot()) << destination; |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5577 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5578 | } |
| 5579 | } else if (constant->IsLongConstant()) { |
| 5580 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5581 | if (destination.IsRegister()) { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5582 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5583 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5584 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5585 | codegen_->Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5586 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5587 | } else if (constant->IsFloatConstant()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5588 | float fp_value = constant->AsFloatConstant()->GetValue(); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5589 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5590 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5591 | codegen_->Load32BitValue(dest, fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5592 | } else { |
| 5593 | DCHECK(destination.IsStackSlot()) << destination; |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5594 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5595 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5596 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5597 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5598 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5599 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5600 | int64_t value = bit_cast<int64_t, double>(fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5601 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5602 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5603 | codegen_->Load64BitValue(dest, fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5604 | } else { |
| 5605 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5606 | codegen_->Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5607 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5608 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5609 | } else if (source.IsFpuRegister()) { |
| 5610 | if (destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5611 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5612 | } else if (destination.IsStackSlot()) { |
| 5613 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5614 | source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5615 | } else if (destination.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5616 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5617 | source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5618 | } else { |
| 5619 | DCHECK(destination.IsSIMDStackSlot()); |
| 5620 | __ movups(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 5621 | source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5622 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5623 | } |
| 5624 | } |
| 5625 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5626 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5627 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5628 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5629 | __ movl(reg, CpuRegister(TMP)); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5630 | } |
| 5631 | |
| Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5632 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5633 | __ movq(CpuRegister(TMP), reg1); |
| 5634 | __ movq(reg1, reg2); |
| 5635 | __ movq(reg2, CpuRegister(TMP)); |
| 5636 | } |
| 5637 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5638 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5639 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5640 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5641 | __ movq(reg, CpuRegister(TMP)); |
| 5642 | } |
| 5643 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5644 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5645 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5646 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5647 | __ movd(reg, CpuRegister(TMP)); |
| 5648 | } |
| 5649 | |
| 5650 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5651 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5652 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5653 | __ movd(reg, CpuRegister(TMP)); |
| 5654 | } |
| 5655 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5656 | void ParallelMoveResolverX86_64::Exchange128(XmmRegister reg, int mem) { |
| 5657 | size_t extra_slot = 2 * kX86_64WordSize; |
| 5658 | __ subq(CpuRegister(RSP), Immediate(extra_slot)); |
| 5659 | __ movups(Address(CpuRegister(RSP), 0), XmmRegister(reg)); |
| 5660 | ExchangeMemory64(0, mem + extra_slot, 2); |
| 5661 | __ movups(XmmRegister(reg), Address(CpuRegister(RSP), 0)); |
| 5662 | __ addq(CpuRegister(RSP), Immediate(extra_slot)); |
| 5663 | } |
| 5664 | |
| 5665 | void ParallelMoveResolverX86_64::ExchangeMemory32(int mem1, int mem2) { |
| 5666 | ScratchRegisterScope ensure_scratch( |
| 5667 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5668 | |
| 5669 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5670 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5671 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5672 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5673 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5674 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5675 | CpuRegister(ensure_scratch.GetRegister())); |
| 5676 | } |
| 5677 | |
| 5678 | void ParallelMoveResolverX86_64::ExchangeMemory64(int mem1, int mem2, int num_of_qwords) { |
| 5679 | ScratchRegisterScope ensure_scratch( |
| 5680 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5681 | |
| 5682 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5683 | |
| 5684 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 5685 | for (int i = 0; i < num_of_qwords; i++) { |
| 5686 | __ movq(CpuRegister(TMP), |
| 5687 | Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5688 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5689 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5690 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), |
| 5691 | CpuRegister(TMP)); |
| 5692 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5693 | CpuRegister(ensure_scratch.GetRegister())); |
| 5694 | stack_offset += kX86_64WordSize; |
| 5695 | } |
| 5696 | } |
| 5697 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5698 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5699 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5700 | Location source = move->GetSource(); |
| 5701 | Location destination = move->GetDestination(); |
| 5702 | |
| 5703 | if (source.IsRegister() && destination.IsRegister()) { |
| Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5704 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5705 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5706 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5707 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5708 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5709 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5710 | ExchangeMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5711 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5712 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5713 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5714 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5715 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5716 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5717 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5718 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5719 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5720 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5721 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5722 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5723 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5724 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5725 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5726 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5727 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5728 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5729 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 5730 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 5731 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 5732 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5733 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 5734 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5735 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5736 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5737 | } |
| 5738 | } |
| 5739 | |
| 5740 | |
| 5741 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5742 | __ pushq(CpuRegister(reg)); |
| 5743 | } |
| 5744 | |
| 5745 | |
| 5746 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5747 | __ popq(CpuRegister(reg)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5748 | } |
| 5749 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5750 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5751 | SlowPathCode* slow_path, CpuRegister class_reg) { |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 5752 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 5753 | const size_t status_byte_offset = |
| 5754 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 5755 | constexpr uint32_t shifted_initialized_value = |
| 5756 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 5757 | |
| 5758 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_initialized_value)); |
| Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 5759 | __ j(kBelow, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5760 | __ Bind(slow_path->GetExitLabel()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5761 | // No need for memory fence, thanks to the x86-64 memory model. |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5762 | } |
| 5763 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5764 | void InstructionCodeGeneratorX86_64::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 5765 | CpuRegister temp) { |
| 5766 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 5767 | uint32_t mask = check->GetBitstringMask(); |
| 5768 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 5769 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 5770 | |
| 5771 | if (mask_bits == 16u) { |
| 5772 | // Compare the bitstring in memory. |
| 5773 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 5774 | } else { |
| 5775 | // /* uint32_t */ temp = temp->status_ |
| 5776 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 5777 | // Compare the bitstring bits using SUB. |
| 5778 | __ subl(temp, Immediate(path_to_root)); |
| 5779 | // Shift out bits that do not contribute to the comparison. |
| 5780 | __ shll(temp, Immediate(32u - mask_bits)); |
| 5781 | } |
| 5782 | } |
| 5783 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5784 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5785 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5786 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5787 | case HLoadClass::LoadKind::kInvalid: |
| 5788 | LOG(FATAL) << "UNREACHABLE"; |
| 5789 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5790 | case HLoadClass::LoadKind::kReferrersClass: |
| 5791 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5792 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5793 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5794 | case HLoadClass::LoadKind::kBssEntry: |
| 5795 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5796 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5797 | case HLoadClass::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5798 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5799 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5800 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5801 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5802 | break; |
| 5803 | } |
| 5804 | return desired_class_load_kind; |
| 5805 | } |
| 5806 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5807 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5808 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5809 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5810 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5811 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5812 | cls, |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5813 | Location::RegisterLocation(RAX), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5814 | Location::RegisterLocation(RAX)); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5815 | return; |
| 5816 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5817 | DCHECK(!cls->NeedsAccessCheck()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5818 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5819 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5820 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5821 | ? LocationSummary::kCallOnSlowPath |
| 5822 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5823 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5824 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5825 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5826 | } |
| 5827 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5828 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5829 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5830 | } |
| 5831 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5832 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5833 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5834 | // Rely on the type resolution and/or initialization to save everything. |
| 5835 | // Custom calling convention: RAX serves as both input and output. |
| 5836 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5837 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5838 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5839 | } else { |
| 5840 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5841 | } |
| 5842 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5843 | } |
| 5844 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5845 | Label* CodeGeneratorX86_64::NewJitRootClassPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5846 | dex::TypeIndex type_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5847 | Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5848 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5849 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5850 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5851 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 5852 | return &info->label; |
| 5853 | } |
| 5854 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5855 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5856 | // move. |
| 5857 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5858 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5859 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5860 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5861 | return; |
| 5862 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5863 | DCHECK(!cls->NeedsAccessCheck()); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5864 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5865 | LocationSummary* locations = cls->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5866 | Location out_loc = locations->Out(); |
| 5867 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5868 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5869 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5870 | ? kWithoutReadBarrier |
| 5871 | : kCompilerReadBarrierOption; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5872 | bool generate_null_check = false; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5873 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5874 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5875 | DCHECK(!cls->CanCallRuntime()); |
| 5876 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5877 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5878 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5879 | GenerateGcRootFieldLoad( |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5880 | cls, |
| 5881 | out_loc, |
| 5882 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5883 | /* fixup_label */ nullptr, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5884 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5885 | break; |
| 5886 | } |
| 5887 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5888 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5889 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5890 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5891 | codegen_->RecordBootImageTypePatch(cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5892 | break; |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5893 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5894 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5895 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5896 | codegen_->RecordBootImageRelRoPatch(codegen_->GetBootImageOffset(cls)); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5897 | break; |
| 5898 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5899 | case HLoadClass::LoadKind::kBssEntry: { |
| 5900 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5901 | /* no_rip */ false); |
| 5902 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 5903 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 5904 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 5905 | generate_null_check = true; |
| 5906 | break; |
| 5907 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5908 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 5909 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 5910 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 5911 | DCHECK_NE(address, 0u); |
| 5912 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| 5913 | break; |
| 5914 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5915 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5916 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5917 | /* no_rip */ true); |
| 5918 | Label* fixup_label = |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5919 | codegen_->NewJitRootClassPatch(cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5920 | // /* GcRoot<mirror::Class> */ out = *address |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5921 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5922 | break; |
| 5923 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5924 | default: |
| 5925 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5926 | UNREACHABLE(); |
| 5927 | } |
| 5928 | |
| 5929 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5930 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame^] | 5931 | SlowPathCode* slow_path = |
| 5932 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64(cls, cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5933 | codegen_->AddSlowPath(slow_path); |
| 5934 | if (generate_null_check) { |
| 5935 | __ testl(out, out); |
| 5936 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5937 | } |
| 5938 | if (cls->MustGenerateClinitCheck()) { |
| 5939 | GenerateClassInitializationCheck(slow_path, out); |
| 5940 | } else { |
| 5941 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5942 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5943 | } |
| 5944 | } |
| 5945 | |
| 5946 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5947 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5948 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5949 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5950 | if (check->HasUses()) { |
| 5951 | locations->SetOut(Location::SameAsFirstInput()); |
| 5952 | } |
| 5953 | } |
| 5954 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 5955 | void LocationsBuilderX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5956 | // Custom calling convention: RAX serves as both input and output. |
| 5957 | Location location = Location::RegisterLocation(RAX); |
| 5958 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 5959 | } |
| 5960 | |
| 5961 | void InstructionCodeGeneratorX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5962 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5963 | } |
| 5964 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5965 | void LocationsBuilderX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5966 | // Custom calling convention: RAX serves as both input and output. |
| 5967 | Location location = Location::RegisterLocation(RAX); |
| 5968 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5969 | } |
| 5970 | |
| 5971 | void InstructionCodeGeneratorX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5972 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5973 | } |
| 5974 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5975 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5976 | // We assume the class to not be null. |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame^] | 5977 | SlowPathCode* slow_path = |
| 5978 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64(check->GetLoadClass(), check); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5979 | codegen_->AddSlowPath(slow_path); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5980 | GenerateClassInitializationCheck(slow_path, |
| 5981 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5982 | } |
| 5983 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5984 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5985 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5986 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5987 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5988 | case HLoadString::LoadKind::kBootImageRelRo: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5989 | case HLoadString::LoadKind::kBssEntry: |
| Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5990 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5991 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5992 | case HLoadString::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 5993 | case HLoadString::LoadKind::kJitTableAddress: |
| 5994 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5995 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5996 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5997 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5998 | } |
| 5999 | return desired_string_load_kind; |
| 6000 | } |
| 6001 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6002 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6003 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6004 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6005 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6006 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 6007 | } else { |
| 6008 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6009 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 6010 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6011 | // Rely on the pResolveString to save everything. |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6012 | // Custom calling convention: RAX serves as both input and output. |
| 6013 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6014 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 6015 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6016 | } else { |
| 6017 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6018 | } |
| 6019 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6020 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6021 | } |
| 6022 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6023 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6024 | dex::StringIndex string_index, |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6025 | Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6026 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6027 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6028 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6029 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6030 | return &info->label; |
| 6031 | } |
| 6032 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6033 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6034 | // move. |
| 6035 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6036 | LocationSummary* locations = load->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6037 | Location out_loc = locations->Out(); |
| 6038 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6039 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6040 | switch (load->GetLoadKind()) { |
| 6041 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6042 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6043 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6044 | codegen_->RecordBootImageStringPatch(load); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6045 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6046 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6047 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6048 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6049 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6050 | codegen_->RecordBootImageRelRoPatch(codegen_->GetBootImageOffset(load)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6051 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6052 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6053 | case HLoadString::LoadKind::kBssEntry: { |
| 6054 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 6055 | /* no_rip */ false); |
| 6056 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 6057 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6058 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6059 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86_64(load); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6060 | codegen_->AddSlowPath(slow_path); |
| 6061 | __ testl(out, out); |
| 6062 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6063 | __ Bind(slow_path->GetExitLabel()); |
| 6064 | return; |
| 6065 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6066 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 6067 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 6068 | DCHECK_NE(address, 0u); |
| 6069 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| 6070 | return; |
| 6071 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6072 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6073 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 6074 | /* no_rip */ true); |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6075 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 6076 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6077 | // /* GcRoot<mirror::String> */ out = *address |
| 6078 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6079 | return; |
| 6080 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6081 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6082 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6083 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6084 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6085 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6086 | // Custom calling convention: RAX serves as both input and output. |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6087 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex().index_)); |
| Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6088 | codegen_->InvokeRuntime(kQuickResolveString, |
| 6089 | load, |
| 6090 | load->GetDexPc()); |
| 6091 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6092 | } |
| 6093 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6094 | static Address GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6095 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6096 | /* no_rip */ true); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6097 | } |
| 6098 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6099 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 6100 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6101 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6102 | locations->SetOut(Location::RequiresRegister()); |
| 6103 | } |
| 6104 | |
| 6105 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6106 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 6107 | } |
| 6108 | |
| 6109 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6110 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6111 | } |
| 6112 | |
| 6113 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6114 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6115 | } |
| 6116 | |
| 6117 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6118 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6119 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6120 | InvokeRuntimeCallingConvention calling_convention; |
| 6121 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6122 | } |
| 6123 | |
| 6124 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6125 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6126 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6127 | } |
| 6128 | |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6129 | // Temp is used for read barrier. |
| 6130 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6131 | if (kEmitCompilerReadBarrier && |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6132 | !kUseBakerReadBarrier && |
| 6133 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6134 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6135 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6136 | return 1; |
| 6137 | } |
| 6138 | return 0; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6139 | } |
| 6140 | |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6141 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 6142 | // interface pointer, the current interface is compared in memory. |
| 6143 | // The other checks have one temp for loading the object's class. |
| 6144 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6145 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6146 | return 2; |
| 6147 | } |
| 6148 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6149 | } |
| 6150 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6151 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6152 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6153 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6154 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6155 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6156 | case TypeCheckKind::kExactCheck: |
| 6157 | case TypeCheckKind::kAbstractClassCheck: |
| 6158 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6159 | case TypeCheckKind::kArrayObjectCheck: { |
| 6160 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6161 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6162 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6163 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6164 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6165 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6166 | case TypeCheckKind::kUnresolvedCheck: |
| 6167 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6168 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6169 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6170 | case TypeCheckKind::kBitstringCheck: |
| 6171 | break; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6172 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6173 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6174 | LocationSummary* locations = |
| 6175 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6176 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6177 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6178 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6179 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6180 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6181 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6182 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6183 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 6184 | } else { |
| 6185 | locations->SetInAt(1, Location::Any()); |
| 6186 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6187 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 6188 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6189 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6190 | } |
| 6191 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6192 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6193 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6194 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6195 | Location obj_loc = locations->InAt(0); |
| 6196 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6197 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6198 | Location out_loc = locations->Out(); |
| 6199 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6200 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6201 | DCHECK_LE(num_temps, 1u); |
| 6202 | Location maybe_temp_loc = (num_temps >= 1u) ? locations->GetTemp(0) : Location::NoLocation(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6203 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6204 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6205 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6206 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6207 | SlowPathCode* slow_path = nullptr; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6208 | NearLabel done, zero; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6209 | |
| 6210 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6211 | // Avoid null check if we know obj is not null. |
| 6212 | if (instruction->MustDoNullCheck()) { |
| 6213 | __ testl(obj, obj); |
| 6214 | __ j(kEqual, &zero); |
| 6215 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6216 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6217 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6218 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6219 | ReadBarrierOption read_barrier_option = |
| 6220 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6221 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6222 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6223 | out_loc, |
| 6224 | obj_loc, |
| 6225 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6226 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6227 | if (cls.IsRegister()) { |
| 6228 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6229 | } else { |
| 6230 | DCHECK(cls.IsStackSlot()) << cls; |
| 6231 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6232 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6233 | if (zero.IsLinked()) { |
| 6234 | // Classes must be equal for the instanceof to succeed. |
| 6235 | __ j(kNotEqual, &zero); |
| 6236 | __ movl(out, Immediate(1)); |
| 6237 | __ jmp(&done); |
| 6238 | } else { |
| 6239 | __ setcc(kEqual, out); |
| 6240 | // setcc only sets the low byte. |
| 6241 | __ andl(out, Immediate(1)); |
| 6242 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6243 | break; |
| 6244 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6245 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6246 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6247 | ReadBarrierOption read_barrier_option = |
| 6248 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6249 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6250 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6251 | out_loc, |
| 6252 | obj_loc, |
| 6253 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6254 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6255 | // If the class is abstract, we eagerly fetch the super class of the |
| 6256 | // object to avoid doing a comparison we know will fail. |
| 6257 | NearLabel loop, success; |
| 6258 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6259 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6260 | GenerateReferenceLoadOneRegister(instruction, |
| 6261 | out_loc, |
| 6262 | super_offset, |
| 6263 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6264 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6265 | __ testl(out, out); |
| 6266 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6267 | __ j(kEqual, &done); |
| 6268 | if (cls.IsRegister()) { |
| 6269 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6270 | } else { |
| 6271 | DCHECK(cls.IsStackSlot()) << cls; |
| 6272 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6273 | } |
| 6274 | __ j(kNotEqual, &loop); |
| 6275 | __ movl(out, Immediate(1)); |
| 6276 | if (zero.IsLinked()) { |
| 6277 | __ jmp(&done); |
| 6278 | } |
| 6279 | break; |
| 6280 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6281 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6282 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6283 | ReadBarrierOption read_barrier_option = |
| 6284 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6285 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6286 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6287 | out_loc, |
| 6288 | obj_loc, |
| 6289 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6290 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6291 | // Walk over the class hierarchy to find a match. |
| 6292 | NearLabel loop, success; |
| 6293 | __ Bind(&loop); |
| 6294 | if (cls.IsRegister()) { |
| 6295 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6296 | } else { |
| 6297 | DCHECK(cls.IsStackSlot()) << cls; |
| 6298 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6299 | } |
| 6300 | __ j(kEqual, &success); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6301 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6302 | GenerateReferenceLoadOneRegister(instruction, |
| 6303 | out_loc, |
| 6304 | super_offset, |
| 6305 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6306 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6307 | __ testl(out, out); |
| 6308 | __ j(kNotEqual, &loop); |
| 6309 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6310 | __ jmp(&done); |
| 6311 | __ Bind(&success); |
| 6312 | __ movl(out, Immediate(1)); |
| 6313 | if (zero.IsLinked()) { |
| 6314 | __ jmp(&done); |
| 6315 | } |
| 6316 | break; |
| 6317 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6318 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6319 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6320 | ReadBarrierOption read_barrier_option = |
| 6321 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6322 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6323 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6324 | out_loc, |
| 6325 | obj_loc, |
| 6326 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6327 | read_barrier_option); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6328 | // Do an exact check. |
| 6329 | NearLabel exact_check; |
| 6330 | if (cls.IsRegister()) { |
| 6331 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6332 | } else { |
| 6333 | DCHECK(cls.IsStackSlot()) << cls; |
| 6334 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6335 | } |
| 6336 | __ j(kEqual, &exact_check); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6337 | // 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] | 6338 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6339 | GenerateReferenceLoadOneRegister(instruction, |
| 6340 | out_loc, |
| 6341 | component_offset, |
| 6342 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6343 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6344 | __ testl(out, out); |
| 6345 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6346 | __ j(kEqual, &done); |
| 6347 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6348 | __ j(kNotEqual, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6349 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6350 | __ movl(out, Immediate(1)); |
| 6351 | __ jmp(&done); |
| 6352 | break; |
| 6353 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6354 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6355 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6356 | // No read barrier since the slow path will retry upon failure. |
| 6357 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6358 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6359 | out_loc, |
| 6360 | obj_loc, |
| 6361 | class_offset, |
| 6362 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6363 | if (cls.IsRegister()) { |
| 6364 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6365 | } else { |
| 6366 | DCHECK(cls.IsStackSlot()) << cls; |
| 6367 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6368 | } |
| 6369 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6370 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6371 | instruction, /* is_fatal */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6372 | codegen_->AddSlowPath(slow_path); |
| 6373 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6374 | __ movl(out, Immediate(1)); |
| 6375 | if (zero.IsLinked()) { |
| 6376 | __ jmp(&done); |
| 6377 | } |
| 6378 | break; |
| 6379 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6380 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6381 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6382 | case TypeCheckKind::kInterfaceCheck: { |
| 6383 | // 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] | 6384 | // into the slow path for the unresolved and interface check |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6385 | // cases. |
| 6386 | // |
| 6387 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6388 | // entry point without resorting to a type checking slow path |
| 6389 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6390 | // require to assign fixed registers for the inputs of this |
| 6391 | // HInstanceOf instruction (following the runtime calling |
| 6392 | // convention), which might be cluttered by the potential first |
| 6393 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6394 | // |
| 6395 | // TODO: Introduce a new runtime entry point taking the object |
| 6396 | // to test (instead of its class) as argument, and let it deal |
| 6397 | // with the read barrier issues. This will let us refactor this |
| 6398 | // case of the `switch` code as it was previously (with a direct |
| 6399 | // call to the runtime not using a type checking slow path). |
| 6400 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6401 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6402 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6403 | instruction, /* is_fatal */ false); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6404 | codegen_->AddSlowPath(slow_path); |
| 6405 | __ jmp(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6406 | if (zero.IsLinked()) { |
| 6407 | __ jmp(&done); |
| 6408 | } |
| 6409 | break; |
| 6410 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6411 | |
| 6412 | case TypeCheckKind::kBitstringCheck: { |
| 6413 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6414 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6415 | out_loc, |
| 6416 | obj_loc, |
| 6417 | class_offset, |
| 6418 | kWithoutReadBarrier); |
| 6419 | |
| 6420 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 6421 | if (zero.IsLinked()) { |
| 6422 | __ j(kNotEqual, &zero); |
| 6423 | __ movl(out, Immediate(1)); |
| 6424 | __ jmp(&done); |
| 6425 | } else { |
| 6426 | __ setcc(kEqual, out); |
| 6427 | // setcc only sets the low byte. |
| 6428 | __ andl(out, Immediate(1)); |
| 6429 | } |
| 6430 | break; |
| 6431 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6432 | } |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6433 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6434 | if (zero.IsLinked()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6435 | __ Bind(&zero); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6436 | __ xorl(out, out); |
| 6437 | } |
| 6438 | |
| 6439 | if (done.IsLinked()) { |
| 6440 | __ Bind(&done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6441 | } |
| 6442 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6443 | if (slow_path != nullptr) { |
| 6444 | __ Bind(slow_path->GetExitLabel()); |
| 6445 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6446 | } |
| 6447 | |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6448 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6449 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6450 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6451 | LocationSummary* locations = |
| 6452 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6453 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6454 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6455 | // Require a register for the interface check since there is a loop that compares the class to |
| 6456 | // a memory address. |
| 6457 | locations->SetInAt(1, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6458 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6459 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6460 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6461 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6462 | } else { |
| 6463 | locations->SetInAt(1, Location::Any()); |
| 6464 | } |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6465 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathX86. |
| 6466 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6467 | } |
| 6468 | |
| 6469 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6470 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6471 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6472 | Location obj_loc = locations->InAt(0); |
| 6473 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6474 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6475 | Location temp_loc = locations->GetTemp(0); |
| 6476 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6477 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6478 | DCHECK_GE(num_temps, 1u); |
| 6479 | DCHECK_LE(num_temps, 2u); |
| 6480 | Location maybe_temp2_loc = (num_temps >= 2u) ? locations->GetTemp(1) : Location::NoLocation(); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6481 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6482 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6483 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6484 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6485 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6486 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6487 | const uint32_t object_array_data_offset = |
| 6488 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6489 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6490 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6491 | SlowPathCode* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6492 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6493 | instruction, is_type_check_slow_path_fatal); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6494 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6495 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6496 | |
| 6497 | NearLabel done; |
| 6498 | // Avoid null check if we know obj is not null. |
| 6499 | if (instruction->MustDoNullCheck()) { |
| 6500 | __ testl(obj, obj); |
| 6501 | __ j(kEqual, &done); |
| 6502 | } |
| 6503 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6504 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6505 | case TypeCheckKind::kExactCheck: |
| 6506 | case TypeCheckKind::kArrayCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6507 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6508 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6509 | temp_loc, |
| 6510 | obj_loc, |
| 6511 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6512 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6513 | if (cls.IsRegister()) { |
| 6514 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6515 | } else { |
| 6516 | DCHECK(cls.IsStackSlot()) << cls; |
| 6517 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6518 | } |
| 6519 | // Jump to slow path for throwing the exception or doing a |
| 6520 | // more involved array check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6521 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6522 | break; |
| 6523 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6524 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6525 | case TypeCheckKind::kAbstractClassCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6526 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6527 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6528 | temp_loc, |
| 6529 | obj_loc, |
| 6530 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6531 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6532 | // If the class is abstract, we eagerly fetch the super class of the |
| 6533 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6534 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6535 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6536 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6537 | GenerateReferenceLoadOneRegister(instruction, |
| 6538 | temp_loc, |
| 6539 | super_offset, |
| 6540 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6541 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6542 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6543 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6544 | // exception. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6545 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6546 | // Otherwise, compare the classes. |
| 6547 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6548 | if (cls.IsRegister()) { |
| 6549 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6550 | } else { |
| 6551 | DCHECK(cls.IsStackSlot()) << cls; |
| 6552 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6553 | } |
| 6554 | __ j(kNotEqual, &loop); |
| 6555 | break; |
| 6556 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6557 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6558 | case TypeCheckKind::kClassHierarchyCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6559 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6560 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6561 | temp_loc, |
| 6562 | obj_loc, |
| 6563 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6564 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6565 | // Walk over the class hierarchy to find a match. |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6566 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6567 | __ Bind(&loop); |
| 6568 | if (cls.IsRegister()) { |
| 6569 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6570 | } else { |
| 6571 | DCHECK(cls.IsStackSlot()) << cls; |
| 6572 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6573 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6574 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6575 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6576 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6577 | GenerateReferenceLoadOneRegister(instruction, |
| 6578 | temp_loc, |
| 6579 | super_offset, |
| 6580 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6581 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6582 | |
| 6583 | // If the class reference currently in `temp` is not null, jump |
| 6584 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6585 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6586 | __ j(kNotZero, &loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6587 | // Otherwise, jump to the slow path to throw the exception. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6588 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6589 | break; |
| 6590 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6591 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6592 | case TypeCheckKind::kArrayObjectCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6593 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6594 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6595 | temp_loc, |
| 6596 | obj_loc, |
| 6597 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6598 | kWithoutReadBarrier); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6599 | // Do an exact check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6600 | NearLabel check_non_primitive_component_type; |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6601 | if (cls.IsRegister()) { |
| 6602 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6603 | } else { |
| 6604 | DCHECK(cls.IsStackSlot()) << cls; |
| 6605 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6606 | } |
| 6607 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6608 | |
| 6609 | // 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] | 6610 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6611 | GenerateReferenceLoadOneRegister(instruction, |
| 6612 | temp_loc, |
| 6613 | component_offset, |
| 6614 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6615 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6616 | |
| 6617 | // If the component type is not null (i.e. the object is indeed |
| 6618 | // an array), jump to label `check_non_primitive_component_type` |
| 6619 | // to further check that this component type is not a primitive |
| 6620 | // type. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6621 | __ testl(temp, temp); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6622 | // Otherwise, jump to the slow path to throw the exception. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6623 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6624 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6625 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6626 | break; |
| 6627 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6628 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6629 | case TypeCheckKind::kUnresolvedCheck: { |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6630 | // We always go into the type check slow path for the unresolved case. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6631 | // |
| 6632 | // We cannot directly call the CheckCast runtime entry point |
| 6633 | // without resorting to a type checking slow path here (i.e. by |
| 6634 | // calling InvokeRuntime directly), as it would require to |
| 6635 | // assign fixed registers for the inputs of this HInstanceOf |
| 6636 | // instruction (following the runtime calling convention), which |
| 6637 | // might be cluttered by the potential first read barrier |
| 6638 | // emission at the beginning of this method. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6639 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6640 | break; |
| 6641 | } |
| 6642 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6643 | case TypeCheckKind::kInterfaceCheck: { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6644 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 6645 | // We can not get false positives by doing this. |
| 6646 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6647 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6648 | temp_loc, |
| 6649 | obj_loc, |
| 6650 | class_offset, |
| 6651 | kWithoutReadBarrier); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6652 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6653 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6654 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6655 | temp_loc, |
| 6656 | temp_loc, |
| 6657 | iftable_offset, |
| 6658 | kWithoutReadBarrier); |
| 6659 | // Iftable is never null. |
| 6660 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
| 6661 | // Maybe poison the `cls` for direct comparison with memory. |
| 6662 | __ MaybePoisonHeapReference(cls.AsRegister<CpuRegister>()); |
| 6663 | // Loop through the iftable and check if any class matches. |
| 6664 | NearLabel start_loop; |
| 6665 | __ Bind(&start_loop); |
| 6666 | // Need to subtract first to handle the empty array case. |
| 6667 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| 6668 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6669 | // Go to next interface if the classes do not match. |
| 6670 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 6671 | CodeGeneratorX86_64::ArrayAddress(temp, |
| 6672 | maybe_temp2_loc, |
| 6673 | TIMES_4, |
| 6674 | object_array_data_offset)); |
| 6675 | __ j(kNotEqual, &start_loop); // Return if same class. |
| 6676 | // If `cls` was poisoned above, unpoison it. |
| 6677 | __ MaybeUnpoisonHeapReference(cls.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6678 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6679 | } |
| 6680 | |
| 6681 | case TypeCheckKind::kBitstringCheck: { |
| 6682 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6683 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6684 | temp_loc, |
| 6685 | obj_loc, |
| 6686 | class_offset, |
| 6687 | kWithoutReadBarrier); |
| 6688 | |
| 6689 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 6690 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 6691 | break; |
| 6692 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6693 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6694 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6695 | if (done.IsLinked()) { |
| 6696 | __ Bind(&done); |
| 6697 | } |
| 6698 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6699 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6700 | } |
| 6701 | |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6702 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6703 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6704 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6705 | InvokeRuntimeCallingConvention calling_convention; |
| 6706 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6707 | } |
| 6708 | |
| 6709 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6710 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6711 | instruction, |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6712 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6713 | if (instruction->IsEnter()) { |
| 6714 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6715 | } else { |
| 6716 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6717 | } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6718 | } |
| 6719 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6720 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6721 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6722 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6723 | |
| 6724 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6725 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6726 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6727 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 6728 | || instruction->GetResultType() == DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6729 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6730 | locations->SetInAt(1, Location::Any()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6731 | locations->SetOut(Location::SameAsFirstInput()); |
| 6732 | } |
| 6733 | |
| 6734 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6735 | HandleBitwiseOperation(instruction); |
| 6736 | } |
| 6737 | |
| 6738 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6739 | HandleBitwiseOperation(instruction); |
| 6740 | } |
| 6741 | |
| 6742 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6743 | HandleBitwiseOperation(instruction); |
| 6744 | } |
| 6745 | |
| 6746 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6747 | LocationSummary* locations = instruction->GetLocations(); |
| 6748 | Location first = locations->InAt(0); |
| 6749 | Location second = locations->InAt(1); |
| 6750 | DCHECK(first.Equals(locations->Out())); |
| 6751 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6752 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6753 | if (second.IsRegister()) { |
| 6754 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6755 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6756 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6757 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6758 | } else { |
| 6759 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6760 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6761 | } |
| 6762 | } else if (second.IsConstant()) { |
| 6763 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6764 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6765 | __ andl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6766 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6767 | __ orl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6768 | } else { |
| 6769 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6770 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6771 | } |
| 6772 | } else { |
| 6773 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6774 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6775 | __ andl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6776 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6777 | __ orl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6778 | } else { |
| 6779 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6780 | __ xorl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6781 | } |
| 6782 | } |
| 6783 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6784 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6785 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6786 | bool second_is_constant = false; |
| 6787 | int64_t value = 0; |
| 6788 | if (second.IsConstant()) { |
| 6789 | second_is_constant = true; |
| 6790 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6791 | } |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6792 | bool is_int32_value = IsInt<32>(value); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6793 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6794 | if (instruction->IsAnd()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6795 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6796 | if (is_int32_value) { |
| 6797 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6798 | } else { |
| 6799 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6800 | } |
| 6801 | } else if (second.IsDoubleStackSlot()) { |
| 6802 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6803 | } else { |
| 6804 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6805 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6806 | } else if (instruction->IsOr()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6807 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6808 | if (is_int32_value) { |
| 6809 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6810 | } else { |
| 6811 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6812 | } |
| 6813 | } else if (second.IsDoubleStackSlot()) { |
| 6814 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6815 | } else { |
| 6816 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6817 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6818 | } else { |
| 6819 | DCHECK(instruction->IsXor()); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6820 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6821 | if (is_int32_value) { |
| 6822 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6823 | } else { |
| 6824 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6825 | } |
| 6826 | } else if (second.IsDoubleStackSlot()) { |
| 6827 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6828 | } else { |
| 6829 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6830 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6831 | } |
| 6832 | } |
| 6833 | } |
| 6834 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6835 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister( |
| 6836 | HInstruction* instruction, |
| 6837 | Location out, |
| 6838 | uint32_t offset, |
| 6839 | Location maybe_temp, |
| 6840 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6841 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6842 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6843 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6844 | if (kUseBakerReadBarrier) { |
| 6845 | // Load with fast path based Baker's read barrier. |
| 6846 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6847 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6848 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6849 | } else { |
| 6850 | // Load with slow path based read barrier. |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6851 | // Save the value of `out` into `maybe_temp` before overwriting it |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6852 | // in the following move operation, as we will need it for the |
| 6853 | // read barrier below. |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6854 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6855 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6856 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6857 | __ movl(out_reg, Address(out_reg, offset)); |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6858 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6859 | } |
| 6860 | } else { |
| 6861 | // Plain load with no read barrier. |
| 6862 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6863 | __ movl(out_reg, Address(out_reg, offset)); |
| 6864 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6865 | } |
| 6866 | } |
| 6867 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6868 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters( |
| 6869 | HInstruction* instruction, |
| 6870 | Location out, |
| 6871 | Location obj, |
| 6872 | uint32_t offset, |
| 6873 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6874 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6875 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6876 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6877 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6878 | if (kUseBakerReadBarrier) { |
| 6879 | // Load with fast path based Baker's read barrier. |
| 6880 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6881 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6882 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6883 | } else { |
| 6884 | // Load with slow path based read barrier. |
| 6885 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6886 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6887 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6888 | } |
| 6889 | } else { |
| 6890 | // Plain load with no read barrier. |
| 6891 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6892 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6893 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6894 | } |
| 6895 | } |
| 6896 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6897 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad( |
| 6898 | HInstruction* instruction, |
| 6899 | Location root, |
| 6900 | const Address& address, |
| 6901 | Label* fixup_label, |
| 6902 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6903 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6904 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6905 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6906 | if (kUseBakerReadBarrier) { |
| 6907 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6908 | // Baker's read barrier are used: |
| 6909 | // |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6910 | // root = obj.field; |
| 6911 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6912 | // if (temp != null) { |
| 6913 | // root = temp(root) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6914 | // } |
| 6915 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6916 | // /* GcRoot<mirror::Object> */ root = *address |
| 6917 | __ movl(root_reg, address); |
| 6918 | if (fixup_label != nullptr) { |
| 6919 | __ Bind(fixup_label); |
| 6920 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6921 | static_assert( |
| 6922 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6923 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6924 | "have different sizes."); |
| 6925 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6926 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6927 | "have different sizes."); |
| 6928 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6929 | // Slow path marking the GC root `root`. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6930 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6931 | instruction, root, /* unpoison_ref_before_marking */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6932 | codegen_->AddSlowPath(slow_path); |
| 6933 | |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6934 | // Test the `Thread::Current()->pReadBarrierMarkReg ## root.reg()` entrypoint. |
| 6935 | const int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6936 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(root.reg()); |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6937 | __ gs()->cmpl(Address::Absolute(entry_point_offset, /* no_rip */ true), Immediate(0)); |
| 6938 | // The entrypoint is null when the GC is not marking. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6939 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6940 | __ Bind(slow_path->GetExitLabel()); |
| 6941 | } else { |
| 6942 | // GC root loaded through a slow path for read barriers other |
| 6943 | // than Baker's. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6944 | // /* GcRoot<mirror::Object>* */ root = address |
| 6945 | __ leaq(root_reg, address); |
| 6946 | if (fixup_label != nullptr) { |
| 6947 | __ Bind(fixup_label); |
| 6948 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6949 | // /* mirror::Object* */ root = root->Read() |
| 6950 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6951 | } |
| 6952 | } else { |
| 6953 | // Plain GC root load with no read barrier. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6954 | // /* GcRoot<mirror::Object> */ root = *address |
| 6955 | __ movl(root_reg, address); |
| 6956 | if (fixup_label != nullptr) { |
| 6957 | __ Bind(fixup_label); |
| 6958 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6959 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6960 | // do not have to unpoison `root_reg` here. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6961 | } |
| 6962 | } |
| 6963 | |
| 6964 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6965 | Location ref, |
| 6966 | CpuRegister obj, |
| 6967 | uint32_t offset, |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6968 | bool needs_null_check) { |
| 6969 | DCHECK(kEmitCompilerReadBarrier); |
| 6970 | DCHECK(kUseBakerReadBarrier); |
| 6971 | |
| 6972 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6973 | Address src(obj, offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6974 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6975 | } |
| 6976 | |
| 6977 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6978 | Location ref, |
| 6979 | CpuRegister obj, |
| 6980 | uint32_t data_offset, |
| 6981 | Location index, |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6982 | bool needs_null_check) { |
| 6983 | DCHECK(kEmitCompilerReadBarrier); |
| 6984 | DCHECK(kUseBakerReadBarrier); |
| 6985 | |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6986 | static_assert( |
| 6987 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6988 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6989 | // /* HeapReference<Object> */ ref = |
| 6990 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6991 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6992 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6993 | } |
| 6994 | |
| 6995 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6996 | Location ref, |
| 6997 | CpuRegister obj, |
| 6998 | const Address& src, |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6999 | bool needs_null_check, |
| 7000 | bool always_update_field, |
| 7001 | CpuRegister* temp1, |
| 7002 | CpuRegister* temp2) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7003 | DCHECK(kEmitCompilerReadBarrier); |
| 7004 | DCHECK(kUseBakerReadBarrier); |
| 7005 | |
| 7006 | // In slow path based read barriers, the read barrier call is |
| 7007 | // inserted after the original load. However, in fast path based |
| 7008 | // Baker's read barriers, we need to perform the load of |
| 7009 | // mirror::Object::monitor_ *before* the original reference load. |
| 7010 | // This load-load ordering is required by the read barrier. |
| 7011 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7012 | // |
| 7013 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7014 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7015 | // HeapReference<Object> ref = *src; // Original reference load. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7016 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7017 | // if (is_gray) { |
| 7018 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7019 | // } |
| 7020 | // |
| 7021 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7022 | // slightly more complex as: |
| 7023 | // - it implements the load-load fence using a data dependency on |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7024 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7025 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 7026 | // 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] | 7027 | // - it performs additional checks that we do not do here for |
| 7028 | // performance reasons. |
| 7029 | |
| 7030 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7031 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7032 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7033 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7034 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7035 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7036 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7037 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7038 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7039 | |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7040 | // if (rb_state == ReadBarrier::GrayState()) |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7041 | // ref = ReadBarrier::Mark(ref); |
| 7042 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7043 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7044 | if (needs_null_check) { |
| 7045 | MaybeRecordImplicitNullCheck(instruction); |
| 7046 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7047 | |
| 7048 | // Load fence to prevent load-load reordering. |
| 7049 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 7050 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7051 | |
| 7052 | // The actual reference load. |
| 7053 | // /* HeapReference<Object> */ ref = *src |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7054 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7055 | |
| 7056 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7057 | // Slow path marking the object `ref` when it is gray. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7058 | SlowPathCode* slow_path; |
| 7059 | if (always_update_field) { |
| 7060 | DCHECK(temp1 != nullptr); |
| 7061 | DCHECK(temp2 != nullptr); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7062 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7063 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp1, *temp2); |
| 7064 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7065 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7066 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7067 | } |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7068 | AddSlowPath(slow_path); |
| 7069 | |
| 7070 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7071 | __ j(kNotZero, slow_path->GetEntryLabel()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7072 | |
| 7073 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7074 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7075 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7076 | __ Bind(slow_path->GetExitLabel()); |
| 7077 | } |
| 7078 | |
| 7079 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7080 | Location out, |
| 7081 | Location ref, |
| 7082 | Location obj, |
| 7083 | uint32_t offset, |
| 7084 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7085 | DCHECK(kEmitCompilerReadBarrier); |
| 7086 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7087 | // Insert a slow path based read barrier *after* the reference load. |
| 7088 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7089 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7090 | // reference will be carried out by the runtime within the slow |
| 7091 | // path. |
| 7092 | // |
| 7093 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7094 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7095 | // not used by the artReadBarrierSlow entry point. |
| 7096 | // |
| 7097 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7098 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7099 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 7100 | AddSlowPath(slow_path); |
| 7101 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7102 | __ jmp(slow_path->GetEntryLabel()); |
| 7103 | __ Bind(slow_path->GetExitLabel()); |
| 7104 | } |
| 7105 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7106 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7107 | Location out, |
| 7108 | Location ref, |
| 7109 | Location obj, |
| 7110 | uint32_t offset, |
| 7111 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7112 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7113 | // Baker's read barriers shall be handled by the fast path |
| 7114 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 7115 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7116 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7117 | // by the runtime within the slow path. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7118 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7119 | } else if (kPoisonHeapReferences) { |
| 7120 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 7121 | } |
| 7122 | } |
| 7123 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7124 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7125 | Location out, |
| 7126 | Location root) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7127 | DCHECK(kEmitCompilerReadBarrier); |
| 7128 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7129 | // Insert a slow path based read barrier *after* the GC root load. |
| 7130 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7131 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7132 | // not need to do anything special for this here. |
| 7133 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7134 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7135 | AddSlowPath(slow_path); |
| 7136 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7137 | __ jmp(slow_path->GetEntryLabel()); |
| 7138 | __ Bind(slow_path->GetExitLabel()); |
| 7139 | } |
| 7140 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7141 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7142 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7143 | LOG(FATAL) << "Unreachable"; |
| 7144 | } |
| 7145 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7146 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7147 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7148 | LOG(FATAL) << "Unreachable"; |
| 7149 | } |
| 7150 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7151 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7152 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7153 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7154 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7155 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7156 | locations->AddTemp(Location::RequiresRegister()); |
| 7157 | locations->AddTemp(Location::RequiresRegister()); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7158 | } |
| 7159 | |
| 7160 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7161 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7162 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7163 | LocationSummary* locations = switch_instr->GetLocations(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7164 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 7165 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 7166 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7167 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7168 | |
| 7169 | // Should we generate smaller inline compare/jumps? |
| 7170 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7171 | // Figure out the correct compare values and jump conditions. |
| 7172 | // Handle the first compare/branch as a special case because it might |
| 7173 | // jump to the default case. |
| 7174 | DCHECK_GT(num_entries, 2u); |
| 7175 | Condition first_condition; |
| 7176 | uint32_t index; |
| 7177 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7178 | if (lower_bound != 0) { |
| 7179 | first_condition = kLess; |
| 7180 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 7181 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7182 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 7183 | |
| 7184 | index = 1; |
| 7185 | } else { |
| 7186 | // Handle all the compare/jumps below. |
| 7187 | first_condition = kBelow; |
| 7188 | index = 0; |
| 7189 | } |
| 7190 | |
| 7191 | // Handle the rest of the compare/jumps. |
| 7192 | for (; index + 1 < num_entries; index += 2) { |
| 7193 | int32_t compare_to_value = lower_bound + index + 1; |
| 7194 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 7195 | // Jump to successors[index] if value < case_value[index]. |
| 7196 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7197 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7198 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7199 | } |
| 7200 | |
| 7201 | if (index != num_entries) { |
| 7202 | // There are an odd number of entries. Handle the last one. |
| 7203 | DCHECK_EQ(index + 1, num_entries); |
| Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 7204 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7205 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 7206 | } |
| 7207 | |
| 7208 | // And the default for any other value. |
| 7209 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7210 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 7211 | } |
| 7212 | return; |
| 7213 | } |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7214 | |
| 7215 | // Remove the bias, if needed. |
| 7216 | Register value_reg_out = value_reg_in.AsRegister(); |
| 7217 | if (lower_bound != 0) { |
| 7218 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 7219 | value_reg_out = temp_reg.AsRegister(); |
| 7220 | } |
| 7221 | CpuRegister value_reg(value_reg_out); |
| 7222 | |
| 7223 | // Is the value in range? |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7224 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7225 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7226 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7227 | // We are in the range of the table. |
| 7228 | // Load the address of the jump table in the constant area. |
| 7229 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7230 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7231 | // Load the (signed) offset from the jump table. |
| 7232 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 7233 | |
| 7234 | // Add the offset to the address of the table base. |
| 7235 | __ addq(temp_reg, base_reg); |
| 7236 | |
| 7237 | // And jump. |
| 7238 | __ jmp(temp_reg); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7239 | } |
| 7240 | |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7241 | void LocationsBuilderX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7242 | ATTRIBUTE_UNUSED) { |
| 7243 | LOG(FATAL) << "Unreachable"; |
| 7244 | } |
| 7245 | |
| 7246 | void InstructionCodeGeneratorX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7247 | ATTRIBUTE_UNUSED) { |
| 7248 | LOG(FATAL) << "Unreachable"; |
| 7249 | } |
| 7250 | |
| Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7251 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 7252 | if (value == 0) { |
| 7253 | __ xorl(dest, dest); |
| 7254 | } else { |
| 7255 | __ movl(dest, Immediate(value)); |
| 7256 | } |
| 7257 | } |
| 7258 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7259 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 7260 | if (value == 0) { |
| Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7261 | // Clears upper bits too. |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7262 | __ xorl(dest, dest); |
| Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 7263 | } else if (IsUint<32>(value)) { |
| 7264 | // 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] | 7265 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 7266 | } else { |
| 7267 | __ movq(dest, Immediate(value)); |
| 7268 | } |
| 7269 | } |
| 7270 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 7271 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 7272 | if (value == 0) { |
| 7273 | __ xorps(dest, dest); |
| 7274 | } else { |
| 7275 | __ movss(dest, LiteralInt32Address(value)); |
| 7276 | } |
| 7277 | } |
| 7278 | |
| 7279 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 7280 | if (value == 0) { |
| 7281 | __ xorpd(dest, dest); |
| 7282 | } else { |
| 7283 | __ movsd(dest, LiteralInt64Address(value)); |
| 7284 | } |
| 7285 | } |
| 7286 | |
| 7287 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 7288 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 7289 | } |
| 7290 | |
| 7291 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 7292 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 7293 | } |
| 7294 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7295 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 7296 | if (value == 0) { |
| 7297 | __ testl(dest, dest); |
| 7298 | } else { |
| 7299 | __ cmpl(dest, Immediate(value)); |
| 7300 | } |
| 7301 | } |
| 7302 | |
| 7303 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 7304 | if (IsInt<32>(value)) { |
| 7305 | if (value == 0) { |
| 7306 | __ testq(dest, dest); |
| 7307 | } else { |
| 7308 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 7309 | } |
| 7310 | } else { |
| 7311 | // Value won't fit in an int. |
| 7312 | __ cmpq(dest, LiteralInt64Address(value)); |
| 7313 | } |
| 7314 | } |
| 7315 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7316 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 7317 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7318 | GenerateIntCompare(lhs_reg, rhs); |
| 7319 | } |
| 7320 | |
| 7321 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7322 | if (rhs.IsConstant()) { |
| 7323 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7324 | Compare32BitValue(lhs, value); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7325 | } else if (rhs.IsStackSlot()) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7326 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7327 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7328 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7329 | } |
| 7330 | } |
| 7331 | |
| 7332 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 7333 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 7334 | if (rhs.IsConstant()) { |
| 7335 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 7336 | Compare64BitValue(lhs_reg, value); |
| 7337 | } else if (rhs.IsDoubleStackSlot()) { |
| 7338 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 7339 | } else { |
| 7340 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 7341 | } |
| 7342 | } |
| 7343 | |
| 7344 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 7345 | Location index, |
| 7346 | ScaleFactor scale, |
| 7347 | uint32_t data_offset) { |
| 7348 | return index.IsConstant() ? |
| 7349 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7350 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 7351 | } |
| 7352 | |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 7353 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 7354 | DCHECK(dest.IsDoubleStackSlot()); |
| 7355 | if (IsInt<32>(value)) { |
| 7356 | // Can move directly as an int32 constant. |
| 7357 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 7358 | Immediate(static_cast<int32_t>(value))); |
| 7359 | } else { |
| 7360 | Load64BitValue(CpuRegister(TMP), value); |
| 7361 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 7362 | } |
| 7363 | } |
| 7364 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7365 | /** |
| 7366 | * Class to handle late fixup of offsets into constant area. |
| 7367 | */ |
| 7368 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 7369 | public: |
| 7370 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 7371 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7372 | |
| 7373 | protected: |
| 7374 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7375 | |
| 7376 | CodeGeneratorX86_64* codegen_; |
| 7377 | |
| 7378 | private: |
| 7379 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7380 | // Patch the correct offset for the instruction. We use the address of the |
| 7381 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 7382 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7383 | int32_t relative_position = constant_offset - pos; |
| 7384 | |
| 7385 | // Patch in the right value. |
| 7386 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7387 | } |
| 7388 | |
| 7389 | // Location in constant area that the fixup refers to. |
| 7390 | size_t offset_into_constant_area_; |
| 7391 | }; |
| 7392 | |
| 7393 | /** |
| 7394 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7395 | * constant area. |
| 7396 | */ |
| 7397 | class JumpTableRIPFixup : public RIPFixup { |
| 7398 | public: |
| 7399 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 7400 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7401 | |
| 7402 | void CreateJumpTable() { |
| 7403 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7404 | |
| 7405 | // Ensure that the reference to the jump table has the correct offset. |
| 7406 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7407 | SetOffset(offset_in_constant_table); |
| 7408 | |
| 7409 | // Compute the offset from the start of the function to this jump table. |
| 7410 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7411 | |
| 7412 | // Populate the jump table with the correct values for the jump table. |
| 7413 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7414 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7415 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7416 | // The value that we want is the target offset - the position of the table. |
| 7417 | for (int32_t i = 0; i < num_entries; i++) { |
| 7418 | HBasicBlock* b = successors[i]; |
| 7419 | Label* l = codegen_->GetLabelOf(b); |
| 7420 | DCHECK(l->IsBound()); |
| 7421 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7422 | assembler->AppendInt32(offset_to_block); |
| 7423 | } |
| 7424 | } |
| 7425 | |
| 7426 | private: |
| 7427 | const HPackedSwitch* switch_instr_; |
| 7428 | }; |
| 7429 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7430 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7431 | // Generate the constant area if needed. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7432 | X86_64Assembler* assembler = GetAssembler(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7433 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7434 | // 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] | 7435 | assembler->Align(4, 0); |
| 7436 | constant_area_start_ = assembler->CodeSize(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7437 | |
| 7438 | // Populate any jump tables. |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7439 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7440 | jump_table->CreateJumpTable(); |
| 7441 | } |
| 7442 | |
| 7443 | // And now add the constant area to the generated code. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7444 | assembler->AddConstantArea(); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7445 | } |
| 7446 | |
| 7447 | // And finish up. |
| 7448 | CodeGenerator::Finalize(allocator); |
| 7449 | } |
| 7450 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7451 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7452 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddDouble(v)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7453 | return Address::RIP(fixup); |
| 7454 | } |
| 7455 | |
| 7456 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7457 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddFloat(v)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7458 | return Address::RIP(fixup); |
| 7459 | } |
| 7460 | |
| 7461 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7462 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt32(v)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7463 | return Address::RIP(fixup); |
| 7464 | } |
| 7465 | |
| 7466 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7467 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt64(v)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7468 | return Address::RIP(fixup); |
| 7469 | } |
| 7470 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7471 | // TODO: trg as memory. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7472 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7473 | if (!trg.IsValid()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7474 | DCHECK_EQ(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7475 | return; |
| 7476 | } |
| 7477 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7478 | DCHECK_NE(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7479 | |
| 7480 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7481 | if (trg.Equals(return_loc)) { |
| 7482 | return; |
| 7483 | } |
| 7484 | |
| 7485 | // Let the parallel move resolver take care of all of this. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7486 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7487 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7488 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7489 | } |
| 7490 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7491 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7492 | // Create a fixup to be used to create and address the jump table. |
| 7493 | JumpTableRIPFixup* table_fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7494 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7495 | |
| 7496 | // We have to populate the jump tables. |
| 7497 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7498 | return Address::RIP(table_fixup); |
| 7499 | } |
| 7500 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7501 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7502 | const Address& addr_high, |
| 7503 | int64_t v, |
| 7504 | HInstruction* instruction) { |
| 7505 | if (IsInt<32>(v)) { |
| 7506 | int32_t v_32 = v; |
| 7507 | __ movq(addr_low, Immediate(v_32)); |
| 7508 | MaybeRecordImplicitNullCheck(instruction); |
| 7509 | } else { |
| 7510 | // Didn't fit in a register. Do it in pieces. |
| 7511 | int32_t low_v = Low32Bits(v); |
| 7512 | int32_t high_v = High32Bits(v); |
| 7513 | __ movl(addr_low, Immediate(low_v)); |
| 7514 | MaybeRecordImplicitNullCheck(instruction); |
| 7515 | __ movl(addr_high, Immediate(high_v)); |
| 7516 | } |
| 7517 | } |
| 7518 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7519 | void CodeGeneratorX86_64::PatchJitRootUse(uint8_t* code, |
| 7520 | const uint8_t* roots_data, |
| 7521 | const PatchInfo<Label>& info, |
| 7522 | uint64_t index_in_table) const { |
| 7523 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7524 | uintptr_t address = |
| 7525 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7526 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7527 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7528 | dchecked_integral_cast<uint32_t>(address); |
| 7529 | } |
| 7530 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7531 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7532 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7533 | StringReference string_reference(info.target_dex_file, dex::StringIndex(info.offset_or_index)); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7534 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7535 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7536 | } |
| 7537 | |
| 7538 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7539 | TypeReference type_reference(info.target_dex_file, dex::TypeIndex(info.offset_or_index)); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7540 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7541 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7542 | } |
| 7543 | } |
| 7544 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7545 | #undef __ |
| 7546 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7547 | } // namespace x86_64 |
| 7548 | } // namespace art |