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 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 19 | #include "arch/x86_64/jni_frame_x86_64.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 20 | #include "art_method-inl.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 21 | #include "class_table.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 22 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 23 | #include "compiled_method.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 26 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 27 | #include "heap_poisoning.h" |
Nicolas Geoffray | 4313ccb | 2020-08-26 17:01:15 +0100 | [diff] [blame] | 28 | #include "interpreter/mterp/nterp.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 29 | #include "intrinsics.h" |
| 30 | #include "intrinsics_x86_64.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 31 | #include "jit/profiling_info.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 32 | #include "linker/linker_patch.h" |
Andreas Gampe | d490129 | 2017-05-30 18:41:34 -0700 | [diff] [blame] | 33 | #include "lock_word.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 34 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 35 | #include "mirror/class-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 36 | #include "mirror/object_reference.h" |
Ulya Trafimovich | 4f388e3 | 2021-06-28 12:39:14 +0100 | [diff] [blame] | 37 | #include "mirror/var_handle.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 38 | #include "scoped_thread_state_change-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 39 | #include "thread.h" |
| 40 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 41 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 42 | #include "utils/x86_64/assembler_x86_64.h" |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 43 | #include "utils/x86_64/constants_x86_64.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 44 | #include "utils/x86_64/managed_register_x86_64.h" |
| 45 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 46 | namespace art { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 47 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 48 | template<class MirrorType> |
| 49 | class GcRoot; |
| 50 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 51 | namespace x86_64 { |
| 52 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 53 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 54 | static constexpr Register kMethodRegisterArgument = RDI; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 55 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 56 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 57 | // generates less code/data with a small num_entries. |
| 58 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 59 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 60 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 61 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 62 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 63 | static constexpr int kC2ConditionMask = 0x400; |
| 64 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 65 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 66 | // Custom calling convention: RAX serves as both input and output. |
| 67 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 68 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 69 | return caller_saves; |
| 70 | } |
| 71 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 72 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 73 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 74 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 76 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 78 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 80 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 81 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 82 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 83 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 84 | // Live registers will be restored in the catch block if caught. |
| 85 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 86 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 87 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 88 | instruction_, |
| 89 | instruction_->GetDexPc(), |
| 90 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 91 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 94 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 95 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 96 | const char* GetDescription() const override { return "NullCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 97 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 98 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 99 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 100 | }; |
| 101 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 102 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 104 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 106 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 107 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 108 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 109 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 110 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 113 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 114 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 115 | const char* GetDescription() const override { return "DivZeroCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 116 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 117 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 118 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 119 | }; |
| 120 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 121 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 122 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 123 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, DataType::Type type, bool is_div) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 124 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 125 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 126 | void EmitNativeCode(CodeGenerator* codegen) override { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 127 | __ Bind(GetEntryLabel()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 128 | if (type_ == DataType::Type::kInt32) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 129 | if (is_div_) { |
| 130 | __ negl(cpu_reg_); |
| 131 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 132 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 135 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 136 | DCHECK_EQ(DataType::Type::kInt64, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 137 | if (is_div_) { |
| 138 | __ negq(cpu_reg_); |
| 139 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 140 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 141 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 142 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 143 | __ jmp(GetExitLabel()); |
| 144 | } |
| 145 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 146 | const char* GetDescription() const override { return "DivRemMinusOneSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 147 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 148 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 149 | const CpuRegister cpu_reg_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 150 | const DataType::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 151 | const bool is_div_; |
| 152 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 155 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 156 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 157 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 158 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 159 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 160 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 161 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 162 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 163 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 164 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 165 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 166 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 167 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 168 | if (successor_ == nullptr) { |
| 169 | __ jmp(GetReturnLabel()); |
| 170 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 171 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 172 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 175 | Label* GetReturnLabel() { |
| 176 | DCHECK(successor_ == nullptr); |
| 177 | return &return_label_; |
| 178 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 179 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 180 | HBasicBlock* GetSuccessor() const { |
| 181 | return successor_; |
| 182 | } |
| 183 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 184 | const char* GetDescription() const override { return "SuspendCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 185 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 186 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 187 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 188 | Label return_label_; |
| 189 | |
| 190 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 191 | }; |
| 192 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 193 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 194 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 195 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 196 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 197 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 198 | void EmitNativeCode(CodeGenerator* codegen) override { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 199 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 200 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 201 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 202 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 203 | // Live registers will be restored in the catch block if caught. |
| 204 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 205 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 206 | // Are we using an array length from memory? |
| 207 | HInstruction* array_length = instruction_->InputAt(1); |
| 208 | Location length_loc = locations->InAt(1); |
| 209 | InvokeRuntimeCallingConvention calling_convention; |
| 210 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 211 | // Load the array length into our temporary. |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 212 | HArrayLength* length = array_length->AsArrayLength(); |
Nicolas Geoffray | 003444a | 2017-10-17 10:58:42 +0100 | [diff] [blame] | 213 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 214 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 215 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 216 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 217 | // Check for conflicts with index. |
| 218 | if (length_loc.Equals(locations->InAt(0))) { |
| 219 | // We know we aren't using parameter 2. |
| 220 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 221 | } |
| 222 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 223 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 224 | __ shrl(length_loc.AsRegister<CpuRegister>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 225 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 226 | } |
| 227 | |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 228 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 229 | // move resolver. |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 230 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 231 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 232 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 233 | DataType::Type::kInt32, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 234 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 235 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 236 | DataType::Type::kInt32); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 237 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 238 | ? kQuickThrowStringBounds |
| 239 | : kQuickThrowArrayBounds; |
| 240 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 241 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 242 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 245 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 246 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 247 | const char* GetDescription() const override { return "BoundsCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 248 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 249 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 250 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 251 | }; |
| 252 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 253 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 254 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 255 | LoadClassSlowPathX86_64(HLoadClass* cls, HInstruction* at) |
| 256 | : SlowPathCode(at), cls_(cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 257 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 258 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 259 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 260 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 261 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 262 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 263 | Location out = locations->Out(); |
| 264 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 265 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 266 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 267 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 268 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 269 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 270 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 272 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 273 | if (must_resolve_type) { |
| 274 | DCHECK(IsSameDexFile(cls_->GetDexFile(), x86_64_codegen->GetGraph()->GetDexFile())); |
| 275 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 276 | __ movl(CpuRegister(RAX), Immediate(type_index.index_)); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 277 | if (cls_->NeedsAccessCheck()) { |
| 278 | CheckEntrypointTypes<kQuickResolveTypeAndVerifyAccess, void*, uint32_t>(); |
| 279 | x86_64_codegen->InvokeRuntime(kQuickResolveTypeAndVerifyAccess, instruction_, dex_pc, this); |
| 280 | } else { |
| 281 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| 282 | x86_64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 283 | } |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 284 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 285 | } else { |
| 286 | DCHECK(must_do_clinit); |
| 287 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 288 | x86_64_codegen->Move(Location::RegisterLocation(RAX), source); |
| 289 | } |
| 290 | if (must_do_clinit) { |
| 291 | x86_64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 292 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 293 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 294 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 295 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 296 | if (out.IsValid()) { |
| 297 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 298 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 301 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 302 | __ jmp(GetExitLabel()); |
| 303 | } |
| 304 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 305 | const char* GetDescription() const override { return "LoadClassSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 306 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 307 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 308 | // The class this slow path will load. |
| 309 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 310 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 311 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 312 | }; |
| 313 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 314 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
| 315 | public: |
| 316 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
| 317 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 318 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 319 | LocationSummary* locations = instruction_->GetLocations(); |
| 320 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 321 | |
| 322 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 323 | __ Bind(GetEntryLabel()); |
| 324 | SaveLiveRegisters(codegen, locations); |
| 325 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 326 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 327 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 328 | __ movl(CpuRegister(RAX), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 329 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
| 330 | instruction_, |
| 331 | instruction_->GetDexPc(), |
| 332 | this); |
| 333 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 334 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 335 | RestoreLiveRegisters(codegen, locations); |
| 336 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 337 | __ jmp(GetExitLabel()); |
| 338 | } |
| 339 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 340 | const char* GetDescription() const override { return "LoadStringSlowPathX86_64"; } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 341 | |
| 342 | private: |
| 343 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 344 | }; |
| 345 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 346 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 347 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 348 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 349 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 350 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 351 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 352 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 353 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 354 | DCHECK(instruction_->IsCheckCast() |
| 355 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 356 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 357 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 358 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 359 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 360 | if (kPoisonHeapReferences && |
| 361 | instruction_->IsCheckCast() && |
| 362 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 363 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 364 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<CpuRegister>()); |
| 365 | } |
| 366 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 367 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 368 | SaveLiveRegisters(codegen, locations); |
| 369 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 370 | |
| 371 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 372 | // move resolver. |
| 373 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 374 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 375 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 376 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 377 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 378 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 379 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 380 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 381 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 382 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 383 | } else { |
| 384 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 385 | x86_64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 386 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 387 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 388 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 389 | if (!is_fatal_) { |
| 390 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 391 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 392 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 393 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 394 | RestoreLiveRegisters(codegen, locations); |
| 395 | __ jmp(GetExitLabel()); |
| 396 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 399 | const char* GetDescription() const override { return "TypeCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 400 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 401 | bool IsFatal() const override { return is_fatal_; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 402 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 403 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 404 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 405 | |
| 406 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 407 | }; |
| 408 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 409 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 410 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 411 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 412 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 413 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 414 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 415 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 416 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 417 | LocationSummary* locations = instruction_->GetLocations(); |
| 418 | SaveLiveRegisters(codegen, locations); |
| 419 | InvokeRuntimeCallingConvention calling_convention; |
| 420 | x86_64_codegen->Load32BitValue( |
| 421 | CpuRegister(calling_convention.GetRegisterAt(0)), |
| 422 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 423 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 424 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 427 | const char* GetDescription() const override { return "DeoptimizationSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 428 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 429 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 430 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 431 | }; |
| 432 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 433 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 434 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 435 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 436 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 437 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 438 | LocationSummary* locations = instruction_->GetLocations(); |
| 439 | __ Bind(GetEntryLabel()); |
| 440 | SaveLiveRegisters(codegen, locations); |
| 441 | |
| 442 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 443 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 444 | parallel_move.AddMove( |
| 445 | locations->InAt(0), |
| 446 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 447 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 448 | nullptr); |
| 449 | parallel_move.AddMove( |
| 450 | locations->InAt(1), |
| 451 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 452 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 453 | nullptr); |
| 454 | parallel_move.AddMove( |
| 455 | locations->InAt(2), |
| 456 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 457 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 458 | nullptr); |
| 459 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 460 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 461 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 462 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 463 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 464 | RestoreLiveRegisters(codegen, locations); |
| 465 | __ jmp(GetExitLabel()); |
| 466 | } |
| 467 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 468 | const char* GetDescription() const override { return "ArraySetSlowPathX86_64"; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 469 | |
| 470 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 471 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 472 | }; |
| 473 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 474 | // Slow path marking an object reference `ref` during a read |
| 475 | // barrier. The field `obj.field` in the object `obj` holding this |
| 476 | // reference does not get updated by this slow path after marking (see |
| 477 | // ReadBarrierMarkAndUpdateFieldSlowPathX86_64 below for that). |
| 478 | // |
| 479 | // This means that after the execution of this slow path, `ref` will |
| 480 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 481 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 482 | // probably still be a from-space reference (unless it gets updated by |
| 483 | // another thread, or if another thread installed another object |
| 484 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 485 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 486 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 487 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, |
| 488 | Location ref, |
| 489 | bool unpoison_ref_before_marking) |
| 490 | : SlowPathCode(instruction), |
| 491 | ref_(ref), |
| 492 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 493 | DCHECK(kEmitCompilerReadBarrier); |
| 494 | } |
| 495 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 496 | const char* GetDescription() const override { return "ReadBarrierMarkSlowPathX86_64"; } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 497 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 498 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 499 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 500 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 501 | Register ref_reg = ref_cpu_reg.AsRegister(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 502 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 503 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 504 | DCHECK(instruction_->IsInstanceFieldGet() || |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 505 | instruction_->IsPredicatedInstanceFieldGet() || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 506 | instruction_->IsStaticFieldGet() || |
| 507 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 508 | instruction_->IsArraySet() || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 509 | instruction_->IsLoadClass() || |
| 510 | instruction_->IsLoadString() || |
| 511 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 512 | instruction_->IsCheckCast() || |
Ulya Trafimovich | 2ee6969 | 2021-05-19 14:15:14 +0100 | [diff] [blame] | 513 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 514 | << "Unexpected instruction in read barrier marking slow path: " |
| 515 | << instruction_->DebugName(); |
| 516 | |
| 517 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 518 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 519 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 520 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 521 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 522 | // No need to save live registers; it's taken care of by the |
| 523 | // entrypoint. Also, there is no need to update the stack mask, |
| 524 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 525 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 526 | DCHECK_NE(ref_reg, RSP); |
| 527 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 528 | // "Compact" slow path, saving two moves. |
| 529 | // |
| 530 | // Instead of using the standard runtime calling convention (input |
| 531 | // and output in R0): |
| 532 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 533 | // RDI <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 534 | // RAX <- ReadBarrierMark(RDI) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 535 | // ref <- RAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 536 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 537 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 538 | // of a dedicated entrypoint: |
| 539 | // |
| 540 | // rX <- ReadBarrierMarkRegX(rX) |
| 541 | // |
| 542 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 543 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 544 | // This runtime call does not require a stack map. |
| 545 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 546 | __ jmp(GetExitLabel()); |
| 547 | } |
| 548 | |
| 549 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 550 | // The location (register) of the marked object reference. |
| 551 | const Location ref_; |
| 552 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 553 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 554 | |
| 555 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 556 | }; |
| 557 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 558 | // Slow path marking an object reference `ref` during a read barrier, |
| 559 | // and if needed, atomically updating the field `obj.field` in the |
| 560 | // object `obj` holding this reference after marking (contrary to |
| 561 | // ReadBarrierMarkSlowPathX86_64 above, which never tries to update |
| 562 | // `obj.field`). |
| 563 | // |
| 564 | // This means that after the execution of this slow path, both `ref` |
| 565 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 566 | // hold the same to-space reference (unless another thread installed |
| 567 | // another object reference (different from `ref`) in `obj.field`). |
| 568 | class ReadBarrierMarkAndUpdateFieldSlowPathX86_64 : public SlowPathCode { |
| 569 | public: |
| 570 | ReadBarrierMarkAndUpdateFieldSlowPathX86_64(HInstruction* instruction, |
| 571 | Location ref, |
| 572 | CpuRegister obj, |
| 573 | const Address& field_addr, |
| 574 | bool unpoison_ref_before_marking, |
| 575 | CpuRegister temp1, |
| 576 | CpuRegister temp2) |
| 577 | : SlowPathCode(instruction), |
| 578 | ref_(ref), |
| 579 | obj_(obj), |
| 580 | field_addr_(field_addr), |
| 581 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 582 | temp1_(temp1), |
| 583 | temp2_(temp2) { |
| 584 | DCHECK(kEmitCompilerReadBarrier); |
| 585 | } |
| 586 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 587 | const char* GetDescription() const override { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 588 | return "ReadBarrierMarkAndUpdateFieldSlowPathX86_64"; |
| 589 | } |
| 590 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 591 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 592 | LocationSummary* locations = instruction_->GetLocations(); |
| 593 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 594 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| 595 | DCHECK(locations->CanCall()); |
| 596 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 597 | // This slow path is only used by the UnsafeCASObject intrinsic. |
Ulya Trafimovich | 4f388e3 | 2021-06-28 12:39:14 +0100 | [diff] [blame] | 598 | DCHECK((instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 599 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 600 | << instruction_->DebugName(); |
| 601 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
Ulya Trafimovich | 4f388e3 | 2021-06-28 12:39:14 +0100 | [diff] [blame] | 602 | Intrinsics intrinsic = instruction_->AsInvoke()->GetIntrinsic(); |
| 603 | static constexpr auto kVarHandleCAS = mirror::VarHandle::AccessModeTemplate::kCompareAndSet; |
| 604 | static constexpr auto kVarHandleCAX = |
| 605 | mirror::VarHandle::AccessModeTemplate::kCompareAndExchange; |
Ulya Trafimovich | 4b0ceb6 | 2021-07-13 12:16:02 +0100 | [diff] [blame] | 606 | static constexpr auto kVarHandleGAU = mirror::VarHandle::AccessModeTemplate::kGetAndUpdate; |
Ulya Trafimovich | 4f388e3 | 2021-06-28 12:39:14 +0100 | [diff] [blame] | 607 | DCHECK(intrinsic == Intrinsics::kUnsafeCASObject || |
| 608 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == kVarHandleCAS || |
Ulya Trafimovich | 4b0ceb6 | 2021-07-13 12:16:02 +0100 | [diff] [blame] | 609 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == kVarHandleCAX || |
| 610 | mirror::VarHandle::GetAccessModeTemplateByIntrinsic(intrinsic) == kVarHandleGAU); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 611 | |
| 612 | __ Bind(GetEntryLabel()); |
| 613 | if (unpoison_ref_before_marking_) { |
| 614 | // Object* ref = ref_addr->AsMirrorPtr() |
| 615 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| 616 | } |
| 617 | |
| 618 | // Save the old (unpoisoned) reference. |
| 619 | __ movl(temp1_, ref_cpu_reg); |
| 620 | |
| 621 | // No need to save live registers; it's taken care of by the |
| 622 | // entrypoint. Also, there is no need to update the stack mask, |
| 623 | // as this runtime call will not trigger a garbage collection. |
| 624 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 625 | DCHECK_NE(ref_reg, RSP); |
| 626 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 627 | // "Compact" slow path, saving two moves. |
| 628 | // |
| 629 | // Instead of using the standard runtime calling convention (input |
| 630 | // and output in R0): |
| 631 | // |
| 632 | // RDI <- ref |
| 633 | // RAX <- ReadBarrierMark(RDI) |
| 634 | // ref <- RAX |
| 635 | // |
| 636 | // we just use rX (the register containing `ref`) as input and output |
| 637 | // of a dedicated entrypoint: |
| 638 | // |
| 639 | // rX <- ReadBarrierMarkRegX(rX) |
| 640 | // |
| 641 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 642 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 643 | // This runtime call does not require a stack map. |
| 644 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 645 | |
| 646 | // If the new reference is different from the old reference, |
| 647 | // update the field in the holder (`*field_addr`). |
| 648 | // |
| 649 | // Note that this field could also hold a different object, if |
| 650 | // another thread had concurrently changed it. In that case, the |
| 651 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 652 | // operation below would abort the CAS, leaving the field as-is. |
| 653 | NearLabel done; |
| 654 | __ cmpl(temp1_, ref_cpu_reg); |
| 655 | __ j(kEqual, &done); |
| 656 | |
| 657 | // Update the the holder's field atomically. This may fail if |
| 658 | // mutator updates before us, but it's OK. This is achived |
| 659 | // using a strong compare-and-set (CAS) operation with relaxed |
| 660 | // memory synchronization ordering, where the expected value is |
| 661 | // the old reference and the desired value is the new reference. |
| 662 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 663 | // instruction, which requires the expected value (the old |
| 664 | // reference) to be in EAX. Save RAX beforehand, and move the |
| 665 | // expected value (stored in `temp1_`) into EAX. |
| 666 | __ movq(temp2_, CpuRegister(RAX)); |
| 667 | __ movl(CpuRegister(RAX), temp1_); |
| 668 | |
| 669 | // Convenience aliases. |
| 670 | CpuRegister base = obj_; |
| 671 | CpuRegister expected = CpuRegister(RAX); |
| 672 | CpuRegister value = ref_cpu_reg; |
| 673 | |
| 674 | bool base_equals_value = (base.AsRegister() == value.AsRegister()); |
| 675 | Register value_reg = ref_reg; |
| 676 | if (kPoisonHeapReferences) { |
| 677 | if (base_equals_value) { |
| 678 | // If `base` and `value` are the same register location, move |
| 679 | // `value_reg` to a temporary register. This way, poisoning |
| 680 | // `value_reg` won't invalidate `base`. |
| 681 | value_reg = temp1_.AsRegister(); |
| 682 | __ movl(CpuRegister(value_reg), base); |
| 683 | } |
| 684 | |
| 685 | // Check that the register allocator did not assign the location |
| 686 | // of `expected` (RAX) to `value` nor to `base`, so that heap |
| 687 | // poisoning (when enabled) works as intended below. |
| 688 | // - If `value` were equal to `expected`, both references would |
| 689 | // be poisoned twice, meaning they would not be poisoned at |
| 690 | // all, as heap poisoning uses address negation. |
| 691 | // - If `base` were equal to `expected`, poisoning `expected` |
| 692 | // would invalidate `base`. |
| 693 | DCHECK_NE(value_reg, expected.AsRegister()); |
| 694 | DCHECK_NE(base.AsRegister(), expected.AsRegister()); |
| 695 | |
| 696 | __ PoisonHeapReference(expected); |
| 697 | __ PoisonHeapReference(CpuRegister(value_reg)); |
| 698 | } |
| 699 | |
| 700 | __ LockCmpxchgl(field_addr_, CpuRegister(value_reg)); |
| 701 | |
| 702 | // If heap poisoning is enabled, we need to unpoison the values |
| 703 | // that were poisoned earlier. |
| 704 | if (kPoisonHeapReferences) { |
| 705 | if (base_equals_value) { |
| 706 | // `value_reg` has been moved to a temporary register, no need |
| 707 | // to unpoison it. |
| 708 | } else { |
| 709 | __ UnpoisonHeapReference(CpuRegister(value_reg)); |
| 710 | } |
| 711 | // No need to unpoison `expected` (RAX), as it is be overwritten below. |
| 712 | } |
| 713 | |
| 714 | // Restore RAX. |
| 715 | __ movq(CpuRegister(RAX), temp2_); |
| 716 | |
| 717 | __ Bind(&done); |
| 718 | __ jmp(GetExitLabel()); |
| 719 | } |
| 720 | |
| 721 | private: |
| 722 | // The location (register) of the marked object reference. |
| 723 | const Location ref_; |
| 724 | // The register containing the object holding the marked object reference field. |
| 725 | const CpuRegister obj_; |
| 726 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 727 | const Address field_addr_; |
| 728 | |
| 729 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 730 | const bool unpoison_ref_before_marking_; |
| 731 | |
| 732 | const CpuRegister temp1_; |
| 733 | const CpuRegister temp2_; |
| 734 | |
| 735 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86_64); |
| 736 | }; |
| 737 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 738 | // Slow path generating a read barrier for a heap reference. |
| 739 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 740 | public: |
| 741 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 742 | Location out, |
| 743 | Location ref, |
| 744 | Location obj, |
| 745 | uint32_t offset, |
| 746 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 747 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 748 | out_(out), |
| 749 | ref_(ref), |
| 750 | obj_(obj), |
| 751 | offset_(offset), |
| 752 | index_(index) { |
| 753 | DCHECK(kEmitCompilerReadBarrier); |
| 754 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 755 | // object has been overwritten by (or after) the heap object |
| 756 | // reference load to be instrumented, e.g.: |
| 757 | // |
| 758 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 759 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 760 | // |
| 761 | // In that case, we have lost the information about the original |
| 762 | // object, and the emitted read barrier cannot work properly. |
| 763 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 764 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 765 | } |
| 766 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 767 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 768 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 769 | LocationSummary* locations = instruction_->GetLocations(); |
| 770 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 771 | DCHECK(locations->CanCall()); |
| 772 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 773 | DCHECK(instruction_->IsInstanceFieldGet() || |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 774 | instruction_->IsPredicatedInstanceFieldGet() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 775 | instruction_->IsStaticFieldGet() || |
| 776 | instruction_->IsArrayGet() || |
| 777 | instruction_->IsInstanceOf() || |
| 778 | instruction_->IsCheckCast() || |
Vladimir Marko | 94d2c81 | 2020-11-05 10:04:45 +0000 | [diff] [blame] | 779 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 780 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 781 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 782 | |
| 783 | __ Bind(GetEntryLabel()); |
| 784 | SaveLiveRegisters(codegen, locations); |
| 785 | |
| 786 | // We may have to change the index's value, but as `index_` is a |
| 787 | // constant member (like other "inputs" of this slow path), |
| 788 | // introduce a copy of it, `index`. |
| 789 | Location index = index_; |
| 790 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 791 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 792 | if (instruction_->IsArrayGet()) { |
| 793 | // Compute real offset and store it in index_. |
| 794 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 795 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 796 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 797 | // We are about to change the value of `index_reg` (see the |
| 798 | // calls to art::x86_64::X86_64Assembler::shll and |
| 799 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 800 | // has not been saved by the previous call to |
| 801 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 802 | // callee-save register -- |
| 803 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 804 | // callee-save registers, as it has been designed with the |
| 805 | // assumption that callee-save registers are supposed to be |
| 806 | // handled by the called function. So, as a callee-save |
| 807 | // register, `index_reg` _would_ eventually be saved onto |
| 808 | // the stack, but it would be too late: we would have |
| 809 | // changed its value earlier. Therefore, we manually save |
| 810 | // it here into another freely available register, |
| 811 | // `free_reg`, chosen of course among the caller-save |
| 812 | // registers (as a callee-save `free_reg` register would |
| 813 | // exhibit the same problem). |
| 814 | // |
| 815 | // Note we could have requested a temporary register from |
| 816 | // the register allocator instead; but we prefer not to, as |
| 817 | // this is a slow path, and we know we can find a |
| 818 | // caller-save register that is available. |
| 819 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 820 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 821 | index_reg = free_reg; |
| 822 | index = Location::RegisterLocation(index_reg); |
| 823 | } else { |
| 824 | // The initial register stored in `index_` has already been |
| 825 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 826 | // (as it is not a callee-save register), so we can freely |
| 827 | // use it. |
| 828 | } |
| 829 | // Shifting the index value contained in `index_reg` by the |
| 830 | // scale factor (2) cannot overflow in practice, as the |
| 831 | // runtime is unable to allocate object arrays with a size |
| 832 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 833 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 834 | static_assert( |
| 835 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 836 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 837 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 838 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 839 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 840 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 841 | // (as in the case of ArrayGet), as it is actually an offset |
| 842 | // to an object field within an object. |
| 843 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 844 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 845 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 846 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 847 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 848 | DCHECK_EQ(offset_, 0U); |
| 849 | DCHECK(index_.IsRegister()); |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | // We're moving two or three locations to locations that could |
| 854 | // overlap, so we need a parallel move resolver. |
| 855 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 856 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 857 | parallel_move.AddMove(ref_, |
| 858 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 859 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 860 | nullptr); |
| 861 | parallel_move.AddMove(obj_, |
| 862 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 863 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 864 | nullptr); |
| 865 | if (index.IsValid()) { |
| 866 | parallel_move.AddMove(index, |
| 867 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 868 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 869 | nullptr); |
| 870 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 871 | } else { |
| 872 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 873 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 874 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 875 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 876 | instruction_, |
| 877 | instruction_->GetDexPc(), |
| 878 | this); |
| 879 | CheckEntrypointTypes< |
| 880 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 881 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 882 | |
| 883 | RestoreLiveRegisters(codegen, locations); |
| 884 | __ jmp(GetExitLabel()); |
| 885 | } |
| 886 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 887 | const char* GetDescription() const override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 888 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 889 | } |
| 890 | |
| 891 | private: |
| 892 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 893 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 894 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 895 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 896 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 897 | return static_cast<CpuRegister>(i); |
| 898 | } |
| 899 | } |
| 900 | // We shall never fail to find a free caller-save register, as |
| 901 | // there are more than two core caller-save registers on x86-64 |
| 902 | // (meaning it is possible to find one which is different from |
| 903 | // `ref` and `obj`). |
| 904 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 905 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 906 | UNREACHABLE(); |
| 907 | } |
| 908 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 909 | const Location out_; |
| 910 | const Location ref_; |
| 911 | const Location obj_; |
| 912 | const uint32_t offset_; |
| 913 | // An additional location containing an index to an array. |
| 914 | // Only used for HArrayGet and the UnsafeGetObject & |
| 915 | // UnsafeGetObjectVolatile intrinsics. |
| 916 | const Location index_; |
| 917 | |
| 918 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 919 | }; |
| 920 | |
| 921 | // Slow path generating a read barrier for a GC root. |
| 922 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 923 | public: |
| 924 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 925 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 926 | DCHECK(kEmitCompilerReadBarrier); |
| 927 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 928 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 929 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 930 | LocationSummary* locations = instruction_->GetLocations(); |
| 931 | DCHECK(locations->CanCall()); |
| 932 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 933 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 934 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 935 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 936 | |
| 937 | __ Bind(GetEntryLabel()); |
| 938 | SaveLiveRegisters(codegen, locations); |
| 939 | |
| 940 | InvokeRuntimeCallingConvention calling_convention; |
| 941 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 942 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 943 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 944 | instruction_, |
| 945 | instruction_->GetDexPc(), |
| 946 | this); |
| 947 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 948 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 949 | |
| 950 | RestoreLiveRegisters(codegen, locations); |
| 951 | __ jmp(GetExitLabel()); |
| 952 | } |
| 953 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 954 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathX86_64"; } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 955 | |
| 956 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 957 | const Location out_; |
| 958 | const Location root_; |
| 959 | |
| 960 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 961 | }; |
| 962 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 963 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 964 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 965 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 966 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 967 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 968 | switch (cond) { |
| 969 | case kCondEQ: return kEqual; |
| 970 | case kCondNE: return kNotEqual; |
| 971 | case kCondLT: return kLess; |
| 972 | case kCondLE: return kLessEqual; |
| 973 | case kCondGT: return kGreater; |
| 974 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 975 | case kCondB: return kBelow; |
| 976 | case kCondBE: return kBelowEqual; |
| 977 | case kCondA: return kAbove; |
| 978 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 979 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 980 | LOG(FATAL) << "Unreachable"; |
| 981 | UNREACHABLE(); |
| 982 | } |
| 983 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 984 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 985 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 986 | switch (cond) { |
| 987 | case kCondEQ: return kEqual; |
| 988 | case kCondNE: return kNotEqual; |
| 989 | case kCondLT: return kBelow; |
| 990 | case kCondLE: return kBelowEqual; |
| 991 | case kCondGT: return kAbove; |
| 992 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 993 | default: break; // should not happen |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 994 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 995 | LOG(FATAL) << "Unreachable"; |
| 996 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 997 | } |
| 998 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 999 | void CodeGeneratorX86_64::BlockNonVolatileXmmRegisters(LocationSummary* locations) { |
| 1000 | // We have to ensure that the native code we call directly (such as @CriticalNative |
| 1001 | // or some intrinsic helpers, say Math.sin()) doesn't clobber the XMM registers |
| 1002 | // which are non-volatile for ART, but volatile for Native calls. This will ensure |
| 1003 | // that they are saved in the prologue and properly restored. |
| 1004 | for (FloatRegister fp_reg : non_volatile_xmm_regs) { |
| 1005 | locations->AddTemp(Location::FpuRegisterLocation(fp_reg)); |
| 1006 | } |
| 1007 | } |
| 1008 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 1009 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 1010 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 1011 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 1012 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 1015 | void CodeGeneratorX86_64::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 1016 | switch (load_kind) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1017 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 1018 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1019 | __ leal(temp.AsRegister<CpuRegister>(), |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 1020 | Address::Absolute(kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1021 | RecordBootImageMethodPatch(invoke); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1022 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1023 | case MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1024 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 1025 | __ movl(temp.AsRegister<CpuRegister>(), |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 1026 | Address::Absolute(kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1027 | RecordBootImageRelRoPatch(GetBootImageOffset(invoke)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1028 | break; |
| 1029 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1030 | case MethodLoadKind::kBssEntry: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1031 | __ movq(temp.AsRegister<CpuRegister>(), |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 1032 | Address::Absolute(kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1033 | RecordMethodBssEntryPatch(invoke); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 1034 | // No need for memory fence, thanks to the x86-64 memory model. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1035 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1036 | } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 1037 | case MethodLoadKind::kJitDirectAddress: { |
| 1038 | Load64BitValue(temp.AsRegister<CpuRegister>(), |
| 1039 | reinterpret_cast<int64_t>(invoke->GetResolvedMethod())); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 1040 | break; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 1041 | } |
| 1042 | case MethodLoadKind::kRuntimeCall: { |
| 1043 | // Test situation, don't do anything. |
| 1044 | break; |
| 1045 | } |
| 1046 | default: { |
| 1047 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 1048 | UNREACHABLE(); |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall( |
| 1054 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| 1055 | // All registers are assumed to be correctly set up. |
| 1056 | |
| 1057 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 1058 | switch (invoke->GetMethodLoadKind()) { |
| 1059 | case MethodLoadKind::kStringInit: { |
| 1060 | // temp = thread->string_init_entrypoint |
| 1061 | uint32_t offset = |
| 1062 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 1063 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip= */ true)); |
| 1064 | break; |
| 1065 | } |
| 1066 | case MethodLoadKind::kRecursive: { |
| 1067 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
| 1068 | break; |
| 1069 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1070 | case MethodLoadKind::kRuntimeCall: { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1071 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 1072 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1073 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1074 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 1075 | // For kCallCriticalNative we skip loading the method and do the call directly. |
| 1076 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| 1077 | break; |
| 1078 | } |
| 1079 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 1080 | default: { |
| 1081 | LoadMethod(invoke->GetMethodLoadKind(), temp, invoke); |
| 1082 | break; |
| 1083 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | switch (invoke->GetCodePtrLocation()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1087 | case CodePtrLocation::kCallSelf: |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1088 | __ call(&frame_entry_label_); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1089 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1090 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1091 | case CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1092 | size_t out_frame_size = |
| 1093 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorX86_64, |
| 1094 | kNativeStackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1095 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1096 | if (invoke->GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative) { |
| 1097 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 1098 | __ call(Address::Absolute(kPlaceholder32BitOffset, /* no_rip= */ false)); |
| 1099 | RecordBootImageJniEntrypointPatch(invoke); |
| 1100 | } else { |
| 1101 | // (callee_method + offset_of_jni_entry_point)() |
| 1102 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1103 | ArtMethod::EntryPointFromJniOffset(kX86_64PointerSize).SizeValue())); |
| 1104 | } |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1105 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 1106 | // Zero-/sign-extend the result when needed due to native and managed ABI mismatch. |
| 1107 | switch (invoke->GetType()) { |
| 1108 | case DataType::Type::kBool: |
| 1109 | __ movzxb(CpuRegister(RAX), CpuRegister(RAX)); |
| 1110 | break; |
| 1111 | case DataType::Type::kInt8: |
| 1112 | __ movsxb(CpuRegister(RAX), CpuRegister(RAX)); |
| 1113 | break; |
| 1114 | case DataType::Type::kUint16: |
| 1115 | __ movzxw(CpuRegister(RAX), CpuRegister(RAX)); |
| 1116 | break; |
| 1117 | case DataType::Type::kInt16: |
| 1118 | __ movsxw(CpuRegister(RAX), CpuRegister(RAX)); |
| 1119 | break; |
| 1120 | case DataType::Type::kInt32: |
| 1121 | case DataType::Type::kInt64: |
| 1122 | case DataType::Type::kFloat32: |
| 1123 | case DataType::Type::kFloat64: |
| 1124 | case DataType::Type::kVoid: |
| 1125 | break; |
| 1126 | default: |
| 1127 | DCHECK(false) << invoke->GetType(); |
| 1128 | break; |
| 1129 | } |
| 1130 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1131 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1132 | } |
| 1133 | break; |
| 1134 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1135 | case CodePtrLocation::kCallArtMethod: |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1136 | // (callee_method + offset_of_quick_compiled_code)() |
| 1137 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1138 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1139 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1140 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1141 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1142 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1143 | |
| 1144 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1145 | } |
| 1146 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1147 | void CodeGeneratorX86_64::GenerateVirtualCall( |
| 1148 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1149 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1150 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1151 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1152 | |
| 1153 | // Use the calling convention instead of the location of the receiver, as |
| 1154 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1155 | // slow path, the arguments have been moved to the right place, so here we are |
| 1156 | // guaranteed that the receiver is the first register of the calling convention. |
| 1157 | InvokeDexCallingConvention calling_convention; |
| 1158 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1159 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1160 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1161 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1162 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1163 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1164 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1165 | // emit a read barrier for the previous class reference load. |
| 1166 | // However this is not required in practice, as this is an |
| 1167 | // intermediate/temporary reference and because the current |
| 1168 | // concurrent copying collector keeps the from-space memory |
| 1169 | // intact/accessible until the end of the marking phase (the |
| 1170 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1171 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 1172 | |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 1173 | MaybeGenerateInlineCacheCheck(invoke, temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 1174 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1175 | // temp = temp->GetMethodAt(method_offset); |
| 1176 | __ movq(temp, Address(temp, method_offset)); |
| 1177 | // call temp->GetEntryPoint(); |
| 1178 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1179 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1180 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1183 | void CodeGeneratorX86_64::RecordBootImageIntrinsicPatch(uint32_t intrinsic_data) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1184 | boot_image_other_patches_.emplace_back(/* target_dex_file= */ nullptr, intrinsic_data); |
| 1185 | __ Bind(&boot_image_other_patches_.back().label); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1186 | } |
| 1187 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1188 | void CodeGeneratorX86_64::RecordBootImageRelRoPatch(uint32_t boot_image_offset) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1189 | boot_image_other_patches_.emplace_back(/* target_dex_file= */ nullptr, boot_image_offset); |
| 1190 | __ Bind(&boot_image_other_patches_.back().label); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 1193 | void CodeGeneratorX86_64::RecordBootImageMethodPatch(HInvoke* invoke) { |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1194 | boot_image_method_patches_.emplace_back(invoke->GetResolvedMethodReference().dex_file, |
| 1195 | invoke->GetResolvedMethodReference().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1196 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 1199 | void CodeGeneratorX86_64::RecordMethodBssEntryPatch(HInvoke* invoke) { |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1200 | DCHECK(IsSameDexFile(GetGraph()->GetDexFile(), *invoke->GetMethodReference().dex_file)); |
| 1201 | method_bss_entry_patches_.emplace_back(invoke->GetMethodReference().dex_file, |
| 1202 | invoke->GetMethodReference().index); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1203 | __ Bind(&method_bss_entry_patches_.back().label); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1204 | } |
| 1205 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1206 | void CodeGeneratorX86_64::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 1207 | boot_image_type_patches_.emplace_back( |
| 1208 | &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1209 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1210 | } |
| 1211 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1212 | Label* CodeGeneratorX86_64::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1213 | ArenaDeque<PatchInfo<Label>>* patches = nullptr; |
| 1214 | switch (load_class->GetLoadKind()) { |
| 1215 | case HLoadClass::LoadKind::kBssEntry: |
| 1216 | patches = &type_bss_entry_patches_; |
| 1217 | break; |
| 1218 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 1219 | patches = &public_type_bss_entry_patches_; |
| 1220 | break; |
| 1221 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 1222 | patches = &package_type_bss_entry_patches_; |
| 1223 | break; |
| 1224 | default: |
| 1225 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 1226 | UNREACHABLE(); |
| 1227 | } |
| 1228 | patches->emplace_back(&load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| 1229 | return &patches->back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1232 | void CodeGeneratorX86_64::RecordBootImageStringPatch(HLoadString* load_string) { |
| 1233 | boot_image_string_patches_.emplace_back( |
| 1234 | &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 1235 | __ Bind(&boot_image_string_patches_.back().label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1236 | } |
| 1237 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1238 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1239 | string_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1240 | &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1241 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1244 | void CodeGeneratorX86_64::RecordBootImageJniEntrypointPatch(HInvokeStaticOrDirect* invoke) { |
| 1245 | boot_image_jni_entrypoint_patches_.emplace_back(invoke->GetResolvedMethodReference().dex_file, |
| 1246 | invoke->GetResolvedMethodReference().index); |
| 1247 | __ Bind(&boot_image_jni_entrypoint_patches_.back().label); |
| 1248 | } |
| 1249 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1250 | void CodeGeneratorX86_64::LoadBootImageAddress(CpuRegister reg, uint32_t boot_image_reference) { |
| 1251 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 1252 | __ leal(reg, |
| 1253 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1254 | RecordBootImageIntrinsicPatch(boot_image_reference); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 1255 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 1256 | __ movl(reg, |
| 1257 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1258 | RecordBootImageRelRoPatch(boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1259 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1260 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1261 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1262 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1263 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1264 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 1265 | } |
| 1266 | } |
| 1267 | |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 1268 | void CodeGeneratorX86_64::LoadIntrinsicDeclaringClass(CpuRegister reg, HInvoke* invoke) { |
| 1269 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1270 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1271 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 1272 | __ leal(reg, |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 1273 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1274 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1275 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 1276 | boot_image_type_patches_.emplace_back(target_method.dex_file, type_idx.index_); |
| 1277 | __ Bind(&boot_image_type_patches_.back().label); |
| 1278 | } else { |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 1279 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 1280 | LoadBootImageAddress(reg, boot_image_offset); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1281 | } |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1282 | } |
| 1283 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1284 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 1285 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 1286 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 1287 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1288 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1289 | inline void CodeGeneratorX86_64::EmitPcRelativeLinkerPatches( |
| 1290 | const ArenaDeque<PatchInfo<Label>>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1291 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1292 | for (const PatchInfo<Label>& info : infos) { |
| 1293 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1294 | linker_patches->push_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1295 | 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] | 1296 | } |
| 1297 | } |
| 1298 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1299 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 1300 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 1301 | const DexFile* target_dex_file, |
| 1302 | uint32_t pc_insn_offset, |
| 1303 | uint32_t boot_image_offset) { |
| 1304 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 1305 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1308 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1309 | DCHECK(linker_patches->empty()); |
| 1310 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1311 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1312 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1313 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1314 | type_bss_entry_patches_.size() + |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1315 | public_type_bss_entry_patches_.size() + |
| 1316 | package_type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1317 | boot_image_string_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1318 | string_bss_entry_patches_.size() + |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1319 | boot_image_jni_entrypoint_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1320 | boot_image_other_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1321 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 1322 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1323 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1324 | boot_image_method_patches_, linker_patches); |
| 1325 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1326 | boot_image_type_patches_, linker_patches); |
| 1327 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1328 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1329 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1330 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1331 | DCHECK(boot_image_type_patches_.empty()); |
| 1332 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1333 | } |
| 1334 | if (GetCompilerOptions().IsBootImage()) { |
| 1335 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 1336 | boot_image_other_patches_, linker_patches); |
| 1337 | } else { |
| 1338 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 1339 | boot_image_other_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1340 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1341 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1342 | method_bss_entry_patches_, linker_patches); |
| 1343 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1344 | type_bss_entry_patches_, linker_patches); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1345 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 1346 | public_type_bss_entry_patches_, linker_patches); |
| 1347 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 1348 | package_type_bss_entry_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1349 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1350 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1351 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeJniEntrypointPatch>( |
| 1352 | boot_image_jni_entrypoint_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1353 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1356 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1357 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1361 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1362 | } |
| 1363 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1364 | const X86_64InstructionSetFeatures& CodeGeneratorX86_64::GetInstructionSetFeatures() const { |
| 1365 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86_64InstructionSetFeatures(); |
| 1366 | } |
| 1367 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1368 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1369 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1370 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1371 | } |
| 1372 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1373 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1374 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1375 | return kX86_64WordSize; |
| 1376 | } |
| 1377 | |
| 1378 | 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] | 1379 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1380 | __ movups(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1381 | } else { |
| 1382 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1383 | } |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1384 | return GetSlowPathFPWidth(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | 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] | 1388 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1389 | __ movups(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1390 | } else { |
| 1391 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1392 | } |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1393 | return GetSlowPathFPWidth(); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1394 | } |
| 1395 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1396 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1397 | HInstruction* instruction, |
| 1398 | uint32_t dex_pc, |
| 1399 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1400 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1401 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1402 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1403 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1404 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1405 | } |
| 1406 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1407 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1408 | HInstruction* instruction, |
| 1409 | SlowPathCode* slow_path) { |
| 1410 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1411 | GenerateInvokeRuntime(entry_point_offset); |
| 1412 | } |
| 1413 | |
| 1414 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1415 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip= */ true)); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1418 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1419 | // Use a fake return address register to mimic Quick. |
| 1420 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1421 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1422 | const CompilerOptions& compiler_options, |
| 1423 | OptimizingCompilerStats* stats) |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1424 | : CodeGenerator(graph, |
| 1425 | kNumberOfCpuRegisters, |
| 1426 | kNumberOfFloatRegisters, |
| 1427 | kNumberOfCpuRegisterPairs, |
| 1428 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1429 | arraysize(kCoreCalleeSaves)) |
| 1430 | | (1 << kFakeReturnRegister), |
| 1431 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1432 | arraysize(kFpuCalleeSaves)), |
| 1433 | compiler_options, |
| 1434 | stats), |
| 1435 | block_labels_(nullptr), |
| 1436 | location_builder_(graph, this), |
| 1437 | instruction_visitor_(graph, this), |
| 1438 | move_resolver_(graph->GetAllocator(), this), |
| 1439 | assembler_(graph->GetAllocator()), |
| 1440 | constant_area_start_(0), |
| 1441 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1442 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1443 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1444 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1445 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1446 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1447 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1448 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1449 | boot_image_jni_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1450 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1451 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1452 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1453 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1454 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1455 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1456 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1457 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1458 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1459 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1460 | assembler_(codegen->GetAssembler()), |
| 1461 | codegen_(codegen) {} |
| 1462 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1463 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1464 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1465 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1466 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1467 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1468 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1469 | } |
| 1470 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1471 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1472 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1473 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1474 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1475 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1476 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1477 | } |
| 1478 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1479 | void CodeGeneratorX86_64::MaybeIncrementHotness(bool is_frame_entry) { |
| 1480 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1481 | NearLabel overflow; |
| 1482 | Register method = kMethodRegisterArgument; |
| 1483 | if (!is_frame_entry) { |
| 1484 | CHECK(RequiresCurrentMethod()); |
| 1485 | method = TMP; |
| 1486 | __ movq(CpuRegister(method), Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 1487 | } |
| 1488 | __ cmpw(Address(CpuRegister(method), ArtMethod::HotnessCountOffset().Int32Value()), |
| 1489 | Immediate(ArtMethod::MaxCounter())); |
| 1490 | __ j(kEqual, &overflow); |
| 1491 | __ addw(Address(CpuRegister(method), ArtMethod::HotnessCountOffset().Int32Value()), |
| 1492 | Immediate(1)); |
| 1493 | __ Bind(&overflow); |
| 1494 | } |
| 1495 | |
| 1496 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 1497 | ScopedProfilingInfoUse spiu( |
| 1498 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 1499 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1500 | if (info != nullptr) { |
| 1501 | uint64_t address = reinterpret_cast64<uint64_t>(info); |
| 1502 | NearLabel done; |
| 1503 | __ movq(CpuRegister(TMP), Immediate(address)); |
| 1504 | __ addw(Address(CpuRegister(TMP), ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), |
| 1505 | Immediate(1)); |
Nicolas Geoffray | 4313ccb | 2020-08-26 17:01:15 +0100 | [diff] [blame] | 1506 | __ andw(Address(CpuRegister(TMP), ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), |
| 1507 | Immediate(interpreter::kTieredHotnessMask)); |
| 1508 | __ j(kNotZero, &done); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1509 | if (HasEmptyFrame()) { |
| 1510 | CHECK(is_frame_entry); |
| 1511 | // Frame alignment, and the stub expects the method on the stack. |
| 1512 | __ pushq(CpuRegister(RDI)); |
| 1513 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1514 | __ cfi().RelOffset(DWARFReg(RDI), 0); |
| 1515 | } else if (!RequiresCurrentMethod()) { |
| 1516 | CHECK(is_frame_entry); |
| 1517 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), CpuRegister(RDI)); |
| 1518 | } |
| 1519 | GenerateInvokeRuntime( |
| 1520 | GetThreadOffset<kX86_64PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 1521 | if (HasEmptyFrame()) { |
| 1522 | __ popq(CpuRegister(RDI)); |
| 1523 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1524 | __ cfi().Restore(DWARFReg(RDI)); |
| 1525 | } |
| 1526 | __ Bind(&done); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1527 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1528 | } |
| 1529 | } |
| 1530 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1531 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1532 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1533 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1534 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1535 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1536 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1537 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1538 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1539 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1540 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86_64); |
| 1541 | __ testq(CpuRegister(RAX), Address(CpuRegister(RSP), -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1542 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1543 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1544 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1545 | if (!HasEmptyFrame()) { |
| 1546 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1547 | Register reg = kCoreCalleeSaves[i]; |
| 1548 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1549 | __ pushq(CpuRegister(reg)); |
| 1550 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1551 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| 1552 | } |
| 1553 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1554 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1555 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1556 | IncreaseFrame(adjust); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1557 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1558 | size_t xmm_spill_slot_size = GetCalleePreservedFPWidth(); |
| 1559 | |
| 1560 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1561 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1562 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1563 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1564 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | // Save the current method if we need it. Note that we do not |
| 1569 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1570 | // in the SSA graph. |
| 1571 | if (RequiresCurrentMethod()) { |
| 1572 | CHECK(!HasEmptyFrame()); |
| 1573 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1574 | CpuRegister(kMethodRegisterArgument)); |
| 1575 | } |
| 1576 | |
| 1577 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1578 | CHECK(!HasEmptyFrame()); |
| 1579 | // Initialize should_deoptimize flag to 0. |
| 1580 | __ movl(Address(CpuRegister(RSP), GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1581 | } |
| 1582 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1583 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1584 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1588 | __ cfi().RememberState(); |
| 1589 | if (!HasEmptyFrame()) { |
| 1590 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1591 | size_t xmm_spill_slot_size = GetCalleePreservedFPWidth(); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1592 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1593 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1594 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1595 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1596 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1601 | DecreaseFrame(adjust); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1602 | |
| 1603 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1604 | Register reg = kCoreCalleeSaves[i]; |
| 1605 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1606 | __ popq(CpuRegister(reg)); |
| 1607 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1608 | __ cfi().Restore(DWARFReg(reg)); |
| 1609 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1610 | } |
| 1611 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1612 | __ ret(); |
| 1613 | __ cfi().RestoreState(); |
| 1614 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1615 | } |
| 1616 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1617 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1618 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1619 | } |
| 1620 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1621 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1622 | if (source.Equals(destination)) { |
| 1623 | return; |
| 1624 | } |
| 1625 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1626 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1627 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1628 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1629 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1630 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1631 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1632 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1633 | } else if (source.IsConstant()) { |
| 1634 | HConstant* constant = source.GetConstant(); |
| 1635 | if (constant->IsLongConstant()) { |
| 1636 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
Ulya Trafimovich | 4f388e3 | 2021-06-28 12:39:14 +0100 | [diff] [blame] | 1637 | } else if (constant->IsDoubleConstant()) { |
| 1638 | Load64BitValue(dest, GetInt64ValueOf(constant)); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1639 | } else { |
| 1640 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1641 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1642 | } else { |
| 1643 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1644 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1645 | } |
| 1646 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1647 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1648 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1649 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1650 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1651 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1652 | } else if (source.IsConstant()) { |
| 1653 | HConstant* constant = source.GetConstant(); |
| 1654 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1655 | if (constant->IsFloatConstant()) { |
| 1656 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1657 | } else { |
| 1658 | Load64BitValue(dest, value); |
| 1659 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1660 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1661 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1662 | } else { |
| 1663 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1664 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1665 | } |
| 1666 | } else if (destination.IsStackSlot()) { |
| 1667 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1668 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1669 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1670 | } else if (source.IsFpuRegister()) { |
| 1671 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1672 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1673 | } else if (source.IsConstant()) { |
| 1674 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1675 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1676 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1677 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1678 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1679 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1680 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1681 | } |
| 1682 | } else { |
| 1683 | DCHECK(destination.IsDoubleStackSlot()); |
| 1684 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1685 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1686 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1687 | } else if (source.IsFpuRegister()) { |
| 1688 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1689 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1690 | } else if (source.IsConstant()) { |
| 1691 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1692 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1693 | int64_t value = GetInt64ValueOf(constant); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1694 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1695 | } else { |
| 1696 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1697 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1698 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | } |
| 1702 | |
Ulya Trafimovich | 161911c | 2021-06-01 15:47:28 +0100 | [diff] [blame] | 1703 | void CodeGeneratorX86_64::LoadFromMemoryNoReference(DataType::Type type, |
| 1704 | Location dst, |
| 1705 | Address src) { |
| 1706 | switch (type) { |
| 1707 | case DataType::Type::kBool: |
| 1708 | case DataType::Type::kUint8: |
| 1709 | __ movzxb(dst.AsRegister<CpuRegister>(), src); |
| 1710 | break; |
| 1711 | case DataType::Type::kInt8: |
| 1712 | __ movsxb(dst.AsRegister<CpuRegister>(), src); |
| 1713 | break; |
| 1714 | case DataType::Type::kUint16: |
| 1715 | __ movzxw(dst.AsRegister<CpuRegister>(), src); |
| 1716 | break; |
| 1717 | case DataType::Type::kInt16: |
| 1718 | __ movsxw(dst.AsRegister<CpuRegister>(), src); |
| 1719 | break; |
| 1720 | case DataType::Type::kInt32: |
| 1721 | case DataType::Type::kUint32: |
| 1722 | __ movl(dst.AsRegister<CpuRegister>(), src); |
| 1723 | break; |
| 1724 | case DataType::Type::kInt64: |
| 1725 | case DataType::Type::kUint64: |
| 1726 | __ movq(dst.AsRegister<CpuRegister>(), src); |
| 1727 | break; |
| 1728 | case DataType::Type::kFloat32: |
| 1729 | __ movss(dst.AsFpuRegister<XmmRegister>(), src); |
| 1730 | break; |
| 1731 | case DataType::Type::kFloat64: |
| 1732 | __ movsd(dst.AsFpuRegister<XmmRegister>(), src); |
| 1733 | break; |
| 1734 | case DataType::Type::kVoid: |
| 1735 | case DataType::Type::kReference: |
| 1736 | LOG(FATAL) << "Unreachable type " << type; |
| 1737 | UNREACHABLE(); |
| 1738 | } |
| 1739 | } |
| 1740 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1741 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1742 | DCHECK(location.IsRegister()); |
| 1743 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1744 | } |
| 1745 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1746 | void CodeGeneratorX86_64::MoveLocation( |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1747 | Location dst, Location src, DataType::Type dst_type ATTRIBUTE_UNUSED) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1748 | Move(dst, src); |
| 1749 | } |
| 1750 | |
| 1751 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1752 | if (location.IsRegister()) { |
| 1753 | locations->AddTemp(location); |
| 1754 | } else { |
| 1755 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1756 | } |
| 1757 | } |
| 1758 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1759 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1760 | if (successor->IsExitBlock()) { |
| 1761 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1762 | return; // no code needed |
| 1763 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1764 | |
| 1765 | HBasicBlock* block = got->GetBlock(); |
| 1766 | HInstruction* previous = got->GetPrevious(); |
| 1767 | |
| 1768 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1769 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1770 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1771 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1772 | return; |
| 1773 | } |
| 1774 | |
| 1775 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1776 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1777 | } |
| 1778 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1779 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1780 | } |
| 1781 | } |
| 1782 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1783 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1784 | got->SetLocations(nullptr); |
| 1785 | } |
| 1786 | |
| 1787 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1788 | HandleGoto(got, got->GetSuccessor()); |
| 1789 | } |
| 1790 | |
| 1791 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1792 | try_boundary->SetLocations(nullptr); |
| 1793 | } |
| 1794 | |
| 1795 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1796 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1797 | if (!successor->IsExitBlock()) { |
| 1798 | HandleGoto(try_boundary, successor); |
| 1799 | } |
| 1800 | } |
| 1801 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1802 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1803 | exit->SetLocations(nullptr); |
| 1804 | } |
| 1805 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1806 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1807 | } |
| 1808 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1809 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1810 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1811 | LabelType* true_label, |
| 1812 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1813 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1814 | __ j(kUnordered, true_label); |
| 1815 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1816 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1817 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1818 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1819 | } |
| 1820 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1821 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1822 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1823 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1824 | Location left = locations->InAt(0); |
| 1825 | Location right = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1826 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1827 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1828 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1829 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1830 | case DataType::Type::kInt8: |
| 1831 | case DataType::Type::kUint16: |
| 1832 | case DataType::Type::kInt16: |
| 1833 | case DataType::Type::kInt32: |
| 1834 | case DataType::Type::kReference: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1835 | codegen_->GenerateIntCompare(left, right); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1836 | break; |
| 1837 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1838 | case DataType::Type::kInt64: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1839 | codegen_->GenerateLongCompare(left, right); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1840 | break; |
| 1841 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1842 | case DataType::Type::kFloat32: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1843 | if (right.IsFpuRegister()) { |
| 1844 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1845 | } else if (right.IsConstant()) { |
| 1846 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1847 | codegen_->LiteralFloatAddress( |
| 1848 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1849 | } else { |
| 1850 | DCHECK(right.IsStackSlot()); |
| 1851 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1852 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1853 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1854 | break; |
| 1855 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1856 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1857 | if (right.IsFpuRegister()) { |
| 1858 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1859 | } else if (right.IsConstant()) { |
| 1860 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1861 | codegen_->LiteralDoubleAddress( |
| 1862 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1863 | } else { |
| 1864 | DCHECK(right.IsDoubleStackSlot()); |
| 1865 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1866 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1867 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1868 | break; |
| 1869 | } |
| 1870 | default: |
| 1871 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | template<class LabelType> |
| 1876 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1877 | LabelType* true_target_in, |
| 1878 | LabelType* false_target_in) { |
| 1879 | // Generated branching requires both targets to be explicit. If either of the |
| 1880 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1881 | LabelType fallthrough_target; |
| 1882 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1883 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1884 | |
| 1885 | // Generate the comparison to set the CC. |
| 1886 | GenerateCompareTest(condition); |
| 1887 | |
| 1888 | // Now generate the correct jump(s). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1889 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1890 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1891 | case DataType::Type::kInt64: { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1892 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1893 | break; |
| 1894 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1895 | case DataType::Type::kFloat32: { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1896 | GenerateFPJumps(condition, true_target, false_target); |
| 1897 | break; |
| 1898 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1899 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1900 | GenerateFPJumps(condition, true_target, false_target); |
| 1901 | break; |
| 1902 | } |
| 1903 | default: |
| 1904 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1905 | } |
| 1906 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1907 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1908 | __ jmp(false_target); |
| 1909 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1910 | |
| 1911 | if (fallthrough_target.IsLinked()) { |
| 1912 | __ Bind(&fallthrough_target); |
| 1913 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1914 | } |
| 1915 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1916 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1917 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1918 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1919 | // conditions if they are materialized due to the complex branching. |
| 1920 | return cond->IsCondition() && |
| 1921 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1922 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1923 | } |
| 1924 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1925 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1926 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1927 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1928 | LabelType* true_target, |
| 1929 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1930 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1931 | |
| 1932 | if (true_target == nullptr && false_target == nullptr) { |
| 1933 | // Nothing to do. The code always falls through. |
| 1934 | return; |
| 1935 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1936 | // Constant condition, statically compared against "true" (integer value 1). |
| 1937 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1938 | if (true_target != nullptr) { |
| 1939 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1940 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1941 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1942 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1943 | if (false_target != nullptr) { |
| 1944 | __ jmp(false_target); |
| 1945 | } |
| 1946 | } |
| 1947 | return; |
| 1948 | } |
| 1949 | |
| 1950 | // The following code generates these patterns: |
| 1951 | // (1) true_target == nullptr && false_target != nullptr |
| 1952 | // - opposite condition true => branch to false_target |
| 1953 | // (2) true_target != nullptr && false_target == nullptr |
| 1954 | // - condition true => branch to true_target |
| 1955 | // (3) true_target != nullptr && false_target != nullptr |
| 1956 | // - condition true => branch to true_target |
| 1957 | // - branch to false_target |
| 1958 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1959 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1960 | if (true_target == nullptr) { |
| 1961 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1962 | } else { |
| 1963 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1964 | } |
| 1965 | } else { |
| 1966 | // Materialized condition, compare against 0. |
| 1967 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1968 | if (lhs.IsRegister()) { |
| 1969 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1970 | } else { |
| 1971 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1972 | } |
| 1973 | if (true_target == nullptr) { |
| 1974 | __ j(kEqual, false_target); |
| 1975 | } else { |
| 1976 | __ j(kNotEqual, true_target); |
| 1977 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1978 | } |
| 1979 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1980 | // Condition has not been materialized, use its inputs as the |
| 1981 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1982 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1983 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1984 | // If this is a long or FP comparison that has been folded into |
| 1985 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1986 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1987 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1988 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1989 | return; |
| 1990 | } |
| 1991 | |
| 1992 | Location lhs = condition->GetLocations()->InAt(0); |
| 1993 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1994 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1995 | if (true_target == nullptr) { |
| 1996 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1997 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1998 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1999 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2000 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2001 | |
| 2002 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2003 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2004 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2005 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2006 | } |
| 2007 | } |
| 2008 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2009 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2010 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2011 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2012 | locations->SetInAt(0, Location::Any()); |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2017 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2018 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 2019 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2020 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2021 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2022 | nullptr : codegen_->GetLabelOf(false_successor); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2023 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2027 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2028 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 2029 | InvokeRuntimeCallingConvention calling_convention; |
| 2030 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2031 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2032 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 2033 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2034 | locations->SetInAt(0, Location::Any()); |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 2039 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2040 | GenerateTestAndBranch<Label>(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2041 | /* condition_input_index= */ 0, |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2042 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2043 | /* false_target= */ nullptr); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2044 | } |
| 2045 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2046 | void LocationsBuilderX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2047 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 2048 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2049 | locations->SetOut(Location::RequiresRegister()); |
| 2050 | } |
| 2051 | |
| 2052 | void InstructionCodeGeneratorX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2053 | __ movl(flag->GetLocations()->Out().AsRegister<CpuRegister>(), |
| 2054 | Address(CpuRegister(RSP), codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 2055 | } |
| 2056 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2057 | static bool SelectCanUseCMOV(HSelect* select) { |
| 2058 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2059 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2060 | return false; |
| 2061 | } |
| 2062 | |
| 2063 | // A FP condition doesn't generate the single CC that we need. |
| 2064 | HInstruction* condition = select->GetCondition(); |
| 2065 | if (condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2066 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2067 | return false; |
| 2068 | } |
| 2069 | |
| 2070 | // We can generate a CMOV for this Select. |
| 2071 | return true; |
| 2072 | } |
| 2073 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2074 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2075 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2076 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2077 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2078 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2079 | } else { |
| 2080 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2081 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 2082 | if (select->InputAt(1)->IsConstant()) { |
| 2083 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2084 | } else { |
| 2085 | locations->SetInAt(1, Location::Any()); |
| 2086 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2087 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2088 | locations->SetInAt(1, Location::Any()); |
| 2089 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2090 | } |
| 2091 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2092 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2093 | } |
| 2094 | locations->SetOut(Location::SameAsFirstInput()); |
| 2095 | } |
| 2096 | |
| 2097 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 2098 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2099 | if (SelectCanUseCMOV(select)) { |
| 2100 | // If both the condition and the source types are integer, we can generate |
| 2101 | // a CMOV to implement Select. |
| 2102 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 2103 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2104 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 2105 | |
| 2106 | HInstruction* select_condition = select->GetCondition(); |
| 2107 | Condition cond = kNotEqual; |
| 2108 | |
| 2109 | // Figure out how to test the 'condition'. |
| 2110 | if (select_condition->IsCondition()) { |
| 2111 | HCondition* condition = select_condition->AsCondition(); |
| 2112 | if (!condition->IsEmittedAtUseSite()) { |
| 2113 | // This was a previously materialized condition. |
| 2114 | // Can we use the existing condition code? |
| 2115 | if (AreEflagsSetFrom(condition, select)) { |
| 2116 | // Materialization was the previous instruction. Condition codes are right. |
| 2117 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 2118 | } else { |
| 2119 | // No, we have to recreate the condition code. |
| 2120 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 2121 | __ testl(cond_reg, cond_reg); |
| 2122 | } |
| 2123 | } else { |
| 2124 | GenerateCompareTest(condition); |
| 2125 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 2126 | } |
| 2127 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 2128 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2129 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 2130 | __ testl(cond_reg, cond_reg); |
| 2131 | } |
| 2132 | |
| 2133 | // If the condition is true, overwrite the output, which already contains false. |
| 2134 | // Generate the correct sized CMOV. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2135 | bool is_64_bit = DataType::Is64BitType(select->GetType()); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 2136 | if (value_true_loc.IsRegister()) { |
| 2137 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 2138 | } else { |
| 2139 | __ cmov(cond, |
| 2140 | value_false, |
| 2141 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 2142 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2143 | } else { |
| 2144 | NearLabel false_target; |
| 2145 | GenerateTestAndBranch<NearLabel>(select, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2146 | /* condition_input_index= */ 2, |
| 2147 | /* true_target= */ nullptr, |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2148 | &false_target); |
| 2149 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2150 | __ Bind(&false_target); |
| 2151 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2154 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2155 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2158 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2159 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2162 | void CodeGeneratorX86_64::IncreaseFrame(size_t adjustment) { |
| 2163 | __ subq(CpuRegister(RSP), Immediate(adjustment)); |
| 2164 | __ cfi().AdjustCFAOffset(adjustment); |
| 2165 | } |
| 2166 | |
| 2167 | void CodeGeneratorX86_64::DecreaseFrame(size_t adjustment) { |
| 2168 | __ addq(CpuRegister(RSP), Immediate(adjustment)); |
| 2169 | __ cfi().AdjustCFAOffset(-adjustment); |
| 2170 | } |
| 2171 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2172 | void CodeGeneratorX86_64::GenerateNop() { |
| 2173 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2176 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2177 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2178 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2179 | // Handle the long/FP comparisons made in instruction simplification. |
| 2180 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2181 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2182 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2183 | locations->SetInAt(1, Location::Any()); |
| 2184 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2185 | case DataType::Type::kFloat32: |
| 2186 | case DataType::Type::kFloat64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2187 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2188 | locations->SetInAt(1, Location::Any()); |
| 2189 | break; |
| 2190 | default: |
| 2191 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2192 | locations->SetInAt(1, Location::Any()); |
| 2193 | break; |
| 2194 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2195 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2196 | locations->SetOut(Location::RequiresRegister()); |
| 2197 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2198 | } |
| 2199 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2200 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2201 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2202 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2203 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2204 | |
| 2205 | LocationSummary* locations = cond->GetLocations(); |
| 2206 | Location lhs = locations->InAt(0); |
| 2207 | Location rhs = locations->InAt(1); |
| 2208 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 2209 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2210 | |
| 2211 | switch (cond->InputAt(0)->GetType()) { |
| 2212 | default: |
| 2213 | // Integer case. |
| 2214 | |
| 2215 | // Clear output register: setcc only sets the low byte. |
| 2216 | __ xorl(reg, reg); |
| 2217 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2218 | codegen_->GenerateIntCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2219 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2220 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2221 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2222 | // Clear output register: setcc only sets the low byte. |
| 2223 | __ xorl(reg, reg); |
| 2224 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2225 | codegen_->GenerateLongCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2226 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2227 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2228 | case DataType::Type::kFloat32: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2229 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 2230 | if (rhs.IsConstant()) { |
| 2231 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 2232 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 2233 | } else if (rhs.IsStackSlot()) { |
| 2234 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 2235 | } else { |
| 2236 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 2237 | } |
| 2238 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2239 | break; |
| 2240 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2241 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2242 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 2243 | if (rhs.IsConstant()) { |
| 2244 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2245 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 2246 | } else if (rhs.IsDoubleStackSlot()) { |
| 2247 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 2248 | } else { |
| 2249 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 2250 | } |
| 2251 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2252 | break; |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2257 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2258 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2259 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2260 | __ Bind(&false_label); |
| 2261 | __ xorl(reg, reg); |
| 2262 | __ jmp(&done_label); |
| 2263 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2264 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2265 | __ Bind(&true_label); |
| 2266 | __ movl(reg, Immediate(1)); |
| 2267 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2271 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2275 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2279 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2283 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2287 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2291 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2295 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2299 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2303 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2307 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2311 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2315 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2316 | } |
| 2317 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2318 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2319 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2323 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2327 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2331 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2335 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2339 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2343 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2347 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2350 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2351 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2352 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2353 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2354 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2355 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2356 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2357 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2358 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2359 | case DataType::Type::kInt32: |
| 2360 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2361 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2362 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2363 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2364 | break; |
| 2365 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2366 | case DataType::Type::kFloat32: |
| 2367 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2368 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2369 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2370 | locations->SetOut(Location::RequiresRegister()); |
| 2371 | break; |
| 2372 | } |
| 2373 | default: |
| 2374 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2375 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2376 | } |
| 2377 | |
| 2378 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2379 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2380 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2381 | Location left = locations->InAt(0); |
| 2382 | Location right = locations->InAt(1); |
| 2383 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2384 | NearLabel less, greater, done; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2385 | DataType::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2386 | Condition less_cond = kLess; |
| 2387 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2388 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2389 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2390 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2391 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2392 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2393 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2394 | case DataType::Type::kInt32: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2395 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2396 | break; |
| 2397 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2398 | case DataType::Type::kInt64: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2399 | codegen_->GenerateLongCompare(left, right); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2400 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2401 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2402 | case DataType::Type::kFloat32: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2403 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2404 | if (right.IsConstant()) { |
| 2405 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2406 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2407 | } else if (right.IsStackSlot()) { |
| 2408 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2409 | } else { |
| 2410 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2411 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2412 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2413 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2414 | break; |
| 2415 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2416 | case DataType::Type::kFloat64: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2417 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2418 | if (right.IsConstant()) { |
| 2419 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2420 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2421 | } else if (right.IsDoubleStackSlot()) { |
| 2422 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2423 | } else { |
| 2424 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2425 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2426 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2427 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2428 | break; |
| 2429 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2430 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2431 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2432 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2433 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2434 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2435 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2436 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2437 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2438 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2439 | __ movl(out, Immediate(1)); |
| 2440 | __ jmp(&done); |
| 2441 | |
| 2442 | __ Bind(&less); |
| 2443 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2444 | |
| 2445 | __ Bind(&done); |
| 2446 | } |
| 2447 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2448 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2449 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2450 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2451 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2452 | } |
| 2453 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2454 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2455 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2456 | } |
| 2457 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2458 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2459 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2460 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2461 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2462 | } |
| 2463 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2464 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2465 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2466 | } |
| 2467 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2468 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2469 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2470 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2471 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2472 | } |
| 2473 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2474 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2475 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2476 | } |
| 2477 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2478 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2479 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2480 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2481 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2482 | } |
| 2483 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2484 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2485 | // Will be generated at use site. |
| 2486 | } |
| 2487 | |
| 2488 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2489 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2490 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2491 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2492 | } |
| 2493 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2494 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2495 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2496 | // Will be generated at use site. |
| 2497 | } |
| 2498 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2499 | void LocationsBuilderX86_64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2500 | constructor_fence->SetLocations(nullptr); |
| 2501 | } |
| 2502 | |
| 2503 | void InstructionCodeGeneratorX86_64::VisitConstructorFence( |
| 2504 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2505 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2506 | } |
| 2507 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2508 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2509 | memory_barrier->SetLocations(nullptr); |
| 2510 | } |
| 2511 | |
| 2512 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2513 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2514 | } |
| 2515 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2516 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2517 | ret->SetLocations(nullptr); |
| 2518 | } |
| 2519 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2520 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2521 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2525 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2526 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2527 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2528 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2529 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2530 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2531 | case DataType::Type::kInt8: |
| 2532 | case DataType::Type::kUint16: |
| 2533 | case DataType::Type::kInt16: |
| 2534 | case DataType::Type::kInt32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2535 | case DataType::Type::kInt64: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2536 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2537 | break; |
| 2538 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2539 | case DataType::Type::kFloat32: |
| 2540 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2541 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2542 | break; |
| 2543 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2544 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2545 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2546 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2550 | switch (ret->InputAt(0)->GetType()) { |
| 2551 | case DataType::Type::kReference: |
| 2552 | case DataType::Type::kBool: |
| 2553 | case DataType::Type::kUint8: |
| 2554 | case DataType::Type::kInt8: |
| 2555 | case DataType::Type::kUint16: |
| 2556 | case DataType::Type::kInt16: |
| 2557 | case DataType::Type::kInt32: |
| 2558 | case DataType::Type::kInt64: |
| 2559 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
| 2560 | break; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2561 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2562 | case DataType::Type::kFloat32: { |
| 2563 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
| 2564 | XMM0); |
| 2565 | // To simplify callers of an OSR method, we put the return value in both |
| 2566 | // floating point and core register. |
| 2567 | if (GetGraph()->IsCompilingOsr()) { |
| 2568 | __ movd(CpuRegister(RAX), XmmRegister(XMM0), /* is64bit= */ false); |
| 2569 | } |
| 2570 | break; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2571 | } |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2572 | case DataType::Type::kFloat64: { |
| 2573 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
| 2574 | XMM0); |
| 2575 | // To simplify callers of an OSR method, we put the return value in both |
| 2576 | // floating point and core register. |
| 2577 | if (GetGraph()->IsCompilingOsr()) { |
| 2578 | __ movd(CpuRegister(RAX), XmmRegister(XMM0), /* is64bit= */ true); |
| 2579 | } |
| 2580 | break; |
| 2581 | } |
| 2582 | |
| 2583 | default: |
| 2584 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2585 | } |
| 2586 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2587 | } |
| 2588 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2589 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2590 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2591 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2592 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2593 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2594 | case DataType::Type::kInt8: |
| 2595 | case DataType::Type::kUint16: |
| 2596 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2597 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2598 | case DataType::Type::kInt32: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2599 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2600 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2601 | return Location::RegisterLocation(RAX); |
| 2602 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2603 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2604 | return Location::NoLocation(); |
| 2605 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2606 | case DataType::Type::kFloat64: |
| 2607 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2608 | return Location::FpuRegisterLocation(XMM0); |
| 2609 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2610 | |
| 2611 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2615 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2616 | } |
| 2617 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2618 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2619 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2620 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2621 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2622 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2623 | case DataType::Type::kInt8: |
| 2624 | case DataType::Type::kUint16: |
| 2625 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2626 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2627 | uint32_t index = gp_index_++; |
| 2628 | stack_index_++; |
| 2629 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2630 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2631 | } else { |
| 2632 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2633 | } |
| 2634 | } |
| 2635 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2636 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2637 | uint32_t index = gp_index_; |
| 2638 | stack_index_ += 2; |
| 2639 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2640 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2641 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2642 | } else { |
| 2643 | gp_index_ += 2; |
| 2644 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2645 | } |
| 2646 | } |
| 2647 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2648 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2649 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2650 | stack_index_++; |
| 2651 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2652 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2653 | } else { |
| 2654 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2655 | } |
| 2656 | } |
| 2657 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2658 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2659 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2660 | stack_index_ += 2; |
| 2661 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2662 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2663 | } else { |
| 2664 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2665 | } |
| 2666 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2667 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2668 | case DataType::Type::kUint32: |
| 2669 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2670 | case DataType::Type::kVoid: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2671 | LOG(FATAL) << "Unexpected parameter type " << type; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 2672 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2673 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2674 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2675 | } |
| 2676 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2677 | Location CriticalNativeCallingConventionVisitorX86_64::GetNextLocation(DataType::Type type) { |
| 2678 | DCHECK_NE(type, DataType::Type::kReference); |
| 2679 | |
| 2680 | Location location = Location::NoLocation(); |
| 2681 | if (DataType::IsFloatingPointType(type)) { |
| 2682 | if (fpr_index_ < kParameterFloatRegistersLength) { |
| 2683 | location = Location::FpuRegisterLocation(kParameterFloatRegisters[fpr_index_]); |
| 2684 | ++fpr_index_; |
| 2685 | } |
| 2686 | } else { |
| 2687 | // Native ABI uses the same registers as managed, except that the method register RDI |
| 2688 | // is a normal argument. |
| 2689 | if (gpr_index_ < 1u + kParameterCoreRegistersLength) { |
| 2690 | location = Location::RegisterLocation( |
| 2691 | gpr_index_ == 0u ? RDI : kParameterCoreRegisters[gpr_index_ - 1u]); |
| 2692 | ++gpr_index_; |
| 2693 | } |
| 2694 | } |
| 2695 | if (location.IsInvalid()) { |
| 2696 | if (DataType::Is64BitType(type)) { |
| 2697 | location = Location::DoubleStackSlot(stack_offset_); |
| 2698 | } else { |
| 2699 | location = Location::StackSlot(stack_offset_); |
| 2700 | } |
| 2701 | stack_offset_ += kFramePointerSize; |
| 2702 | |
| 2703 | if (for_register_allocation_) { |
| 2704 | location = Location::Any(); |
| 2705 | } |
| 2706 | } |
| 2707 | return location; |
| 2708 | } |
| 2709 | |
| 2710 | Location CriticalNativeCallingConventionVisitorX86_64::GetReturnLocation(DataType::Type type) |
| 2711 | const { |
| 2712 | // We perform conversion to the managed ABI return register after the call if needed. |
| 2713 | InvokeDexCallingConventionVisitorX86_64 dex_calling_convention; |
| 2714 | return dex_calling_convention.GetReturnLocation(type); |
| 2715 | } |
| 2716 | |
| 2717 | Location CriticalNativeCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2718 | // Pass the method in the hidden argument RAX. |
| 2719 | return Location::RegisterLocation(RAX); |
| 2720 | } |
| 2721 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2722 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2723 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2724 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2725 | // the method_idx. |
| 2726 | HandleInvoke(invoke); |
| 2727 | } |
| 2728 | |
| 2729 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2730 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2731 | } |
| 2732 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2733 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2734 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2735 | // art::PrepareForRegisterAllocation. |
| 2736 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2737 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2738 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2739 | if (intrinsic.TryDispatch(invoke)) { |
| 2740 | return; |
| 2741 | } |
| 2742 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 2743 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2744 | CriticalNativeCallingConventionVisitorX86_64 calling_convention_visitor( |
| 2745 | /*for_register_allocation=*/ true); |
| 2746 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 2747 | CodeGeneratorX86_64::BlockNonVolatileXmmRegisters(invoke->GetLocations()); |
| 2748 | } else { |
| 2749 | HandleInvoke(invoke); |
| 2750 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2751 | } |
| 2752 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2753 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2754 | if (invoke->GetLocations()->Intrinsified()) { |
| 2755 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2756 | intrinsic.Dispatch(invoke); |
| 2757 | return true; |
| 2758 | } |
| 2759 | return false; |
| 2760 | } |
| 2761 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2762 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2763 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2764 | // art::PrepareForRegisterAllocation. |
| 2765 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2766 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2767 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2768 | return; |
| 2769 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2770 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2771 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2772 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2773 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2774 | } |
| 2775 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2776 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2777 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2778 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2779 | } |
| 2780 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2781 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2782 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2783 | if (intrinsic.TryDispatch(invoke)) { |
| 2784 | return; |
| 2785 | } |
| 2786 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2787 | HandleInvoke(invoke); |
| 2788 | } |
| 2789 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2790 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2791 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2792 | return; |
| 2793 | } |
| 2794 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2795 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2796 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2797 | } |
| 2798 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2799 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2800 | HandleInvoke(invoke); |
| 2801 | // Add the hidden argument. |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2802 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 2803 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, |
| 2804 | Location::RegisterLocation(RAX)); |
| 2805 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2806 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2807 | } |
| 2808 | |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 2809 | void CodeGeneratorX86_64::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 2810 | CpuRegister klass) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2811 | DCHECK_EQ(RDI, klass.AsRegister()); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 2812 | // We know the destination of an intrinsic, so no need to record inline |
| 2813 | // caches. |
| 2814 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2815 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 2816 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 2817 | ScopedProfilingInfoUse spiu( |
| 2818 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 2819 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2820 | if (info != nullptr) { |
| 2821 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 2822 | uint64_t address = reinterpret_cast64<uint64_t>(cache); |
| 2823 | NearLabel done; |
| 2824 | __ movq(CpuRegister(TMP), Immediate(address)); |
| 2825 | // Fast path for a monomorphic cache. |
| 2826 | __ cmpl(Address(CpuRegister(TMP), InlineCache::ClassesOffset().Int32Value()), klass); |
| 2827 | __ j(kEqual, &done); |
| 2828 | GenerateInvokeRuntime( |
| 2829 | GetThreadOffset<kX86_64PointerSize>(kQuickUpdateInlineCache).Int32Value()); |
| 2830 | __ Bind(&done); |
| 2831 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2832 | } |
| 2833 | } |
| 2834 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2835 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2836 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2837 | LocationSummary* locations = invoke->GetLocations(); |
| 2838 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2839 | Location receiver = locations->InAt(0); |
| 2840 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2841 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2842 | if (receiver.IsStackSlot()) { |
| 2843 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2844 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2845 | __ movl(temp, Address(temp, class_offset)); |
| 2846 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2847 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2848 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2849 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2850 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2851 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2852 | // emit a read barrier for the previous class reference load. |
| 2853 | // However this is not required in practice, as this is an |
| 2854 | // intermediate/temporary reference and because the current |
| 2855 | // concurrent copying collector keeps the from-space memory |
| 2856 | // intact/accessible until the end of the marking phase (the |
| 2857 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2858 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2859 | |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 2860 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2861 | |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 2862 | if (invoke->GetHiddenArgumentLoadKind() != MethodLoadKind::kRecursive && |
| 2863 | invoke->GetHiddenArgumentLoadKind() != MethodLoadKind::kRuntimeCall) { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2864 | Location hidden_reg = locations->GetTemp(1); |
| 2865 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2866 | // won't be modified thereafter, before the `call` instruction. |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 2867 | // We also do it after MaybeGenerateInlineCache that may use RAX. |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2868 | DCHECK_EQ(RAX, hidden_reg.AsRegister<Register>()); |
| 2869 | codegen_->LoadMethod(invoke->GetHiddenArgumentLoadKind(), hidden_reg, invoke); |
| 2870 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2871 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2872 | // temp = temp->GetAddressOfIMT() |
| 2873 | __ movq(temp, |
| 2874 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2875 | // temp = temp->GetImtEntryAt(method_offset); |
| 2876 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2877 | invoke->GetImtIndex(), kX86_64PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2878 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2879 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame] | 2880 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRuntimeCall) { |
| 2881 | // We pass the method from the IMT in case of a conflict. This will ensure |
| 2882 | // we go into the runtime to resolve the actual method. |
| 2883 | Location hidden_reg = locations->GetTemp(1); |
| 2884 | __ movq(hidden_reg.AsRegister<CpuRegister>(), temp); |
| 2885 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2886 | // call temp->GetEntryPoint(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2887 | __ call(Address( |
| 2888 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2889 | |
| 2890 | DCHECK(!codegen_->IsLeafMethod()); |
| 2891 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2892 | } |
| 2893 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2894 | void LocationsBuilderX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 2895 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| 2896 | if (intrinsic.TryDispatch(invoke)) { |
| 2897 | return; |
| 2898 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2899 | HandleInvoke(invoke); |
| 2900 | } |
| 2901 | |
| 2902 | void InstructionCodeGeneratorX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 2903 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2904 | return; |
| 2905 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2906 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2907 | } |
| 2908 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2909 | void LocationsBuilderX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2910 | HandleInvoke(invoke); |
| 2911 | } |
| 2912 | |
| 2913 | void InstructionCodeGeneratorX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2914 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2915 | } |
| 2916 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2917 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2918 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2919 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2920 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2921 | case DataType::Type::kInt32: |
| 2922 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2923 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2924 | locations->SetOut(Location::SameAsFirstInput()); |
| 2925 | break; |
| 2926 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2927 | case DataType::Type::kFloat32: |
| 2928 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2929 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2930 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2931 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2932 | break; |
| 2933 | |
| 2934 | default: |
| 2935 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2940 | LocationSummary* locations = neg->GetLocations(); |
| 2941 | Location out = locations->Out(); |
| 2942 | Location in = locations->InAt(0); |
| 2943 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2944 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2945 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2946 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2947 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2948 | break; |
| 2949 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2950 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2951 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2952 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2953 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2954 | break; |
| 2955 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2956 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2957 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2958 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2959 | // Implement float negation with an exclusive or with value |
| 2960 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2961 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2962 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2963 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2964 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2965 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2966 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2967 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2968 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2969 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2970 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2971 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2972 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2973 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2974 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2975 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2976 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2977 | |
| 2978 | default: |
| 2979 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2980 | } |
| 2981 | } |
| 2982 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2983 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2984 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2985 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2986 | DataType::Type result_type = conversion->GetResultType(); |
| 2987 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2988 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2989 | << input_type << " -> " << result_type; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2990 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2991 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2992 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2993 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2994 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2995 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2996 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2997 | locations->SetInAt(0, Location::Any()); |
| 2998 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2999 | break; |
| 3000 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3001 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3002 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3003 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3004 | locations->SetInAt(0, Location::Any()); |
| 3005 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3006 | break; |
| 3007 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3008 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3009 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3010 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3011 | break; |
| 3012 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3013 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3014 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3015 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3016 | break; |
| 3017 | |
| 3018 | default: |
| 3019 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3020 | << " to " << result_type; |
| 3021 | } |
| 3022 | break; |
| 3023 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3024 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3025 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3026 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3027 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3028 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3029 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3030 | case DataType::Type::kInt16: |
| 3031 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3032 | // TODO: We would benefit from a (to-be-implemented) |
| 3033 | // Location::RegisterOrStackSlot requirement for this input. |
| 3034 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3035 | locations->SetOut(Location::RequiresRegister()); |
| 3036 | break; |
| 3037 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3038 | case DataType::Type::kFloat32: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3039 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3040 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3041 | break; |
| 3042 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3043 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3044 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3045 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3046 | break; |
| 3047 | |
| 3048 | default: |
| 3049 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3050 | << " to " << result_type; |
| 3051 | } |
| 3052 | break; |
| 3053 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3054 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3055 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3056 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3057 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3058 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3059 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3060 | case DataType::Type::kInt16: |
| 3061 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3062 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3063 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3064 | break; |
| 3065 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3066 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3067 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3068 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3069 | break; |
| 3070 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3071 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3072 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3073 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3074 | break; |
| 3075 | |
| 3076 | default: |
| 3077 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3078 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3079 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3080 | break; |
| 3081 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3082 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3083 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3084 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3085 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3086 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3087 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3088 | case DataType::Type::kInt16: |
| 3089 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3090 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3091 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3092 | break; |
| 3093 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3094 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3095 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3096 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3097 | break; |
| 3098 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3099 | case DataType::Type::kFloat32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3100 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3101 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3102 | break; |
| 3103 | |
| 3104 | default: |
| 3105 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3106 | << " to " << result_type; |
| 3107 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3108 | break; |
| 3109 | |
| 3110 | default: |
| 3111 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3112 | << " to " << result_type; |
| 3113 | } |
| 3114 | } |
| 3115 | |
| 3116 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 3117 | LocationSummary* locations = conversion->GetLocations(); |
| 3118 | Location out = locations->Out(); |
| 3119 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3120 | DataType::Type result_type = conversion->GetResultType(); |
| 3121 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3122 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3123 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3124 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3125 | case DataType::Type::kUint8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3126 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3127 | case DataType::Type::kInt8: |
| 3128 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3129 | case DataType::Type::kInt16: |
| 3130 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3131 | case DataType::Type::kInt64: |
| 3132 | if (in.IsRegister()) { |
| 3133 | __ movzxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 3134 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 3135 | __ movzxb(out.AsRegister<CpuRegister>(), |
| 3136 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3137 | } else { |
| 3138 | __ movl(out.AsRegister<CpuRegister>(), |
| 3139 | Immediate(static_cast<uint8_t>(Int64FromConstant(in.GetConstant())))); |
| 3140 | } |
| 3141 | break; |
| 3142 | |
| 3143 | default: |
| 3144 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3145 | << " to " << result_type; |
| 3146 | } |
| 3147 | break; |
| 3148 | |
| 3149 | case DataType::Type::kInt8: |
| 3150 | switch (input_type) { |
| 3151 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3152 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3153 | case DataType::Type::kInt16: |
| 3154 | case DataType::Type::kInt32: |
| 3155 | case DataType::Type::kInt64: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3156 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3157 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3158 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3159 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3160 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3161 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3162 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3163 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3164 | } |
| 3165 | break; |
| 3166 | |
| 3167 | default: |
| 3168 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3169 | << " to " << result_type; |
| 3170 | } |
| 3171 | break; |
| 3172 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3173 | case DataType::Type::kUint16: |
| 3174 | switch (input_type) { |
| 3175 | case DataType::Type::kInt8: |
| 3176 | case DataType::Type::kInt16: |
| 3177 | case DataType::Type::kInt32: |
| 3178 | case DataType::Type::kInt64: |
| 3179 | if (in.IsRegister()) { |
| 3180 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 3181 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 3182 | __ movzxw(out.AsRegister<CpuRegister>(), |
| 3183 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3184 | } else { |
| 3185 | __ movl(out.AsRegister<CpuRegister>(), |
| 3186 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
| 3187 | } |
| 3188 | break; |
| 3189 | |
| 3190 | default: |
| 3191 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3192 | << " to " << result_type; |
| 3193 | } |
| 3194 | break; |
| 3195 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3196 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3197 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3198 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3199 | case DataType::Type::kInt32: |
| 3200 | case DataType::Type::kInt64: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3201 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3202 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3203 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3204 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3205 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3206 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3207 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3208 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3209 | } |
| 3210 | break; |
| 3211 | |
| 3212 | default: |
| 3213 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3214 | << " to " << result_type; |
| 3215 | } |
| 3216 | break; |
| 3217 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3218 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3219 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3220 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3221 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3222 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3223 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3224 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3225 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3226 | } else { |
| 3227 | DCHECK(in.IsConstant()); |
| 3228 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3229 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3230 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3231 | } |
| 3232 | break; |
| 3233 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3234 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3235 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3236 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3237 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3238 | |
| 3239 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 3240 | // if input >= (float)INT_MAX goto done |
Nick Desaulniers | 98e97c6 | 2019-10-18 14:25:19 -0700 | [diff] [blame] | 3241 | __ comiss(input, codegen_->LiteralFloatAddress(static_cast<float>(kPrimIntMax))); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3242 | __ j(kAboveEqual, &done); |
| 3243 | // if input == NaN goto nan |
| 3244 | __ j(kUnordered, &nan); |
| 3245 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3246 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3247 | __ jmp(&done); |
| 3248 | __ Bind(&nan); |
| 3249 | // output = 0 |
| 3250 | __ xorl(output, output); |
| 3251 | __ Bind(&done); |
| 3252 | break; |
| 3253 | } |
| 3254 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3255 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3256 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3257 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3258 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3259 | |
| 3260 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 3261 | // if input >= (double)INT_MAX goto done |
| 3262 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3263 | __ j(kAboveEqual, &done); |
| 3264 | // if input == NaN goto nan |
| 3265 | __ j(kUnordered, &nan); |
| 3266 | // output = double-to-int-truncate(input) |
| 3267 | __ cvttsd2si(output, input); |
| 3268 | __ jmp(&done); |
| 3269 | __ Bind(&nan); |
| 3270 | // output = 0 |
| 3271 | __ xorl(output, output); |
| 3272 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3273 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3274 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3275 | |
| 3276 | default: |
| 3277 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3278 | << " to " << result_type; |
| 3279 | } |
| 3280 | break; |
| 3281 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3282 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3283 | switch (input_type) { |
| 3284 | DCHECK(out.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3285 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3286 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3287 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3288 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3289 | case DataType::Type::kInt16: |
| 3290 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3291 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3292 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3293 | break; |
| 3294 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3295 | case DataType::Type::kFloat32: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3296 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3297 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3298 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3299 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3300 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 3301 | // if input >= (float)LONG_MAX goto done |
Nick Desaulniers | 98e97c6 | 2019-10-18 14:25:19 -0700 | [diff] [blame] | 3302 | __ comiss(input, codegen_->LiteralFloatAddress(static_cast<float>(kPrimLongMax))); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3303 | __ j(kAboveEqual, &done); |
| 3304 | // if input == NaN goto nan |
| 3305 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3306 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3307 | __ cvttss2si(output, input, true); |
| 3308 | __ jmp(&done); |
| 3309 | __ Bind(&nan); |
| 3310 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3311 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3312 | __ Bind(&done); |
| 3313 | break; |
| 3314 | } |
| 3315 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3316 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3317 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3318 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3319 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3320 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3321 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 3322 | // if input >= (double)LONG_MAX goto done |
Nick Desaulniers | 98e97c6 | 2019-10-18 14:25:19 -0700 | [diff] [blame] | 3323 | __ comisd(input, codegen_->LiteralDoubleAddress( |
| 3324 | static_cast<double>(kPrimLongMax))); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3325 | __ j(kAboveEqual, &done); |
| 3326 | // if input == NaN goto nan |
| 3327 | __ j(kUnordered, &nan); |
| 3328 | // output = double-to-long-truncate(input) |
| 3329 | __ cvttsd2si(output, input, true); |
| 3330 | __ jmp(&done); |
| 3331 | __ Bind(&nan); |
| 3332 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3333 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3334 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3335 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3336 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3337 | |
| 3338 | default: |
| 3339 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3340 | << " to " << result_type; |
| 3341 | } |
| 3342 | break; |
| 3343 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3344 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3345 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3346 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3347 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3348 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3349 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3350 | case DataType::Type::kInt16: |
| 3351 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3352 | if (in.IsRegister()) { |
| 3353 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3354 | } else if (in.IsConstant()) { |
| 3355 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3356 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3357 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3358 | } else { |
| 3359 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3360 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3361 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3362 | break; |
| 3363 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3364 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3365 | if (in.IsRegister()) { |
| 3366 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3367 | } else if (in.IsConstant()) { |
| 3368 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3369 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 3370 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3371 | } else { |
| 3372 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3373 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3374 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3375 | break; |
| 3376 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3377 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3378 | if (in.IsFpuRegister()) { |
| 3379 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3380 | } else if (in.IsConstant()) { |
| 3381 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 3382 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3383 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3384 | } else { |
| 3385 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 3386 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3387 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3388 | break; |
| 3389 | |
| 3390 | default: |
| 3391 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3392 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3393 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3394 | break; |
| 3395 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3396 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3397 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3398 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3399 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3400 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3401 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3402 | case DataType::Type::kInt16: |
| 3403 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3404 | if (in.IsRegister()) { |
| 3405 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3406 | } else if (in.IsConstant()) { |
| 3407 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3408 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3409 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3410 | } else { |
| 3411 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3412 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3413 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3414 | break; |
| 3415 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3416 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3417 | if (in.IsRegister()) { |
| 3418 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3419 | } else if (in.IsConstant()) { |
| 3420 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3421 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3422 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3423 | } else { |
| 3424 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3425 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3426 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3427 | break; |
| 3428 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3429 | case DataType::Type::kFloat32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3430 | if (in.IsFpuRegister()) { |
| 3431 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3432 | } else if (in.IsConstant()) { |
| 3433 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3434 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3435 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3436 | } else { |
| 3437 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3438 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3439 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3440 | break; |
| 3441 | |
| 3442 | default: |
| 3443 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3444 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3445 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3446 | break; |
| 3447 | |
| 3448 | default: |
| 3449 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3450 | << " to " << result_type; |
| 3451 | } |
| 3452 | } |
| 3453 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3454 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3455 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3456 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3457 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3458 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3459 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3460 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3461 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3462 | break; |
| 3463 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3464 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3465 | case DataType::Type::kInt64: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3466 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3467 | // 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] | 3468 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3469 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3470 | break; |
| 3471 | } |
| 3472 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3473 | case DataType::Type::kFloat64: |
| 3474 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3475 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3476 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3477 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3478 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3479 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3480 | |
| 3481 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3482 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3483 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3484 | } |
| 3485 | |
| 3486 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3487 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3488 | Location first = locations->InAt(0); |
| 3489 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3490 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3491 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3492 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3493 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3494 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3495 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3496 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3497 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3498 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3499 | } else { |
| 3500 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3501 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3502 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3503 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3504 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3505 | __ addl(out.AsRegister<CpuRegister>(), |
| 3506 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3507 | } else { |
| 3508 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3509 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3510 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3511 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3512 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3513 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3514 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3515 | break; |
| 3516 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3517 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3518 | case DataType::Type::kInt64: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3519 | if (second.IsRegister()) { |
| 3520 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3521 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3522 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3523 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3524 | } else { |
| 3525 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3526 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3527 | } |
| 3528 | } else { |
| 3529 | DCHECK(second.IsConstant()); |
| 3530 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3531 | int32_t int32_value = Low32Bits(value); |
| 3532 | DCHECK_EQ(int32_value, value); |
| 3533 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3534 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3535 | } else { |
| 3536 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3537 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3538 | } |
| 3539 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3540 | break; |
| 3541 | } |
| 3542 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3543 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3544 | if (second.IsFpuRegister()) { |
| 3545 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3546 | } else if (second.IsConstant()) { |
| 3547 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3548 | codegen_->LiteralFloatAddress( |
| 3549 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3550 | } else { |
| 3551 | DCHECK(second.IsStackSlot()); |
| 3552 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3553 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3554 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3555 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3556 | } |
| 3557 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3558 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3559 | if (second.IsFpuRegister()) { |
| 3560 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3561 | } else if (second.IsConstant()) { |
| 3562 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3563 | codegen_->LiteralDoubleAddress( |
| 3564 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3565 | } else { |
| 3566 | DCHECK(second.IsDoubleStackSlot()); |
| 3567 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3568 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3569 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3570 | break; |
| 3571 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3572 | |
| 3573 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3574 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3579 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3580 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3581 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3582 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3583 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3584 | locations->SetInAt(1, Location::Any()); |
| 3585 | locations->SetOut(Location::SameAsFirstInput()); |
| 3586 | break; |
| 3587 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3588 | case DataType::Type::kInt64: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3589 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3590 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3591 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3592 | break; |
| 3593 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3594 | case DataType::Type::kFloat32: |
| 3595 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3596 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3597 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3598 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3599 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3600 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3601 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3602 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3603 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3604 | } |
| 3605 | |
| 3606 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3607 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3608 | Location first = locations->InAt(0); |
| 3609 | Location second = locations->InAt(1); |
| 3610 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3611 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3612 | case DataType::Type::kInt32: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3613 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3614 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3615 | } else if (second.IsConstant()) { |
| 3616 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3617 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3618 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3619 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3620 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3621 | break; |
| 3622 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3623 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3624 | if (second.IsConstant()) { |
| 3625 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3626 | DCHECK(IsInt<32>(value)); |
| 3627 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3628 | } else { |
| 3629 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3630 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3631 | break; |
| 3632 | } |
| 3633 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3634 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3635 | if (second.IsFpuRegister()) { |
| 3636 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3637 | } else if (second.IsConstant()) { |
| 3638 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3639 | codegen_->LiteralFloatAddress( |
| 3640 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3641 | } else { |
| 3642 | DCHECK(second.IsStackSlot()); |
| 3643 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3644 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3645 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3646 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3647 | } |
| 3648 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3649 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3650 | if (second.IsFpuRegister()) { |
| 3651 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3652 | } else if (second.IsConstant()) { |
| 3653 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3654 | codegen_->LiteralDoubleAddress( |
| 3655 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3656 | } else { |
| 3657 | DCHECK(second.IsDoubleStackSlot()); |
| 3658 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3659 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3660 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3661 | break; |
| 3662 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3663 | |
| 3664 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3665 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3666 | } |
| 3667 | } |
| 3668 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3669 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3670 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3671 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3672 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3673 | case DataType::Type::kInt32: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3674 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3675 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3676 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3677 | // Can use 3 operand multiply. |
| 3678 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3679 | } else { |
| 3680 | locations->SetOut(Location::SameAsFirstInput()); |
| 3681 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3682 | break; |
| 3683 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3684 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3685 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3686 | locations->SetInAt(1, Location::Any()); |
| 3687 | if (mul->InputAt(1)->IsLongConstant() && |
| 3688 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3689 | // Can use 3 operand multiply. |
| 3690 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3691 | } else { |
| 3692 | locations->SetOut(Location::SameAsFirstInput()); |
| 3693 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3694 | break; |
| 3695 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3696 | case DataType::Type::kFloat32: |
| 3697 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3698 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3699 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3700 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3701 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3702 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3703 | |
| 3704 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3705 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3706 | } |
| 3707 | } |
| 3708 | |
| 3709 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3710 | LocationSummary* locations = mul->GetLocations(); |
| 3711 | Location first = locations->InAt(0); |
| 3712 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3713 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3714 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3715 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3716 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3717 | // problems where the output may not be the same as the first operand. |
| 3718 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3719 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3720 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3721 | } else if (second.IsRegister()) { |
| 3722 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3723 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3724 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3725 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3726 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3727 | __ imull(first.AsRegister<CpuRegister>(), |
| 3728 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3729 | } |
| 3730 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3731 | case DataType::Type::kInt64: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3732 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3733 | // problems where the output may not be the same as the first operand. |
| 3734 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3735 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3736 | if (IsInt<32>(value)) { |
| 3737 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3738 | Immediate(static_cast<int32_t>(value))); |
| 3739 | } else { |
| 3740 | // Have to use the constant area. |
| 3741 | DCHECK(first.Equals(out)); |
| 3742 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3743 | } |
| 3744 | } else if (second.IsRegister()) { |
| 3745 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3746 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3747 | } else { |
| 3748 | DCHECK(second.IsDoubleStackSlot()); |
| 3749 | DCHECK(first.Equals(out)); |
| 3750 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3751 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3752 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3753 | break; |
| 3754 | } |
| 3755 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3756 | case DataType::Type::kFloat32: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3757 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3758 | if (second.IsFpuRegister()) { |
| 3759 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3760 | } else if (second.IsConstant()) { |
| 3761 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3762 | codegen_->LiteralFloatAddress( |
| 3763 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3764 | } else { |
| 3765 | DCHECK(second.IsStackSlot()); |
| 3766 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3767 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3768 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3769 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3770 | } |
| 3771 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3772 | case DataType::Type::kFloat64: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3773 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3774 | if (second.IsFpuRegister()) { |
| 3775 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3776 | } else if (second.IsConstant()) { |
| 3777 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3778 | codegen_->LiteralDoubleAddress( |
| 3779 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3780 | } else { |
| 3781 | DCHECK(second.IsDoubleStackSlot()); |
| 3782 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3783 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3784 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3785 | break; |
| 3786 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3787 | |
| 3788 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3789 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3790 | } |
| 3791 | } |
| 3792 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3793 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3794 | uint32_t stack_adjustment, bool is_float) { |
| 3795 | if (source.IsStackSlot()) { |
| 3796 | DCHECK(is_float); |
| 3797 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3798 | } else if (source.IsDoubleStackSlot()) { |
| 3799 | DCHECK(!is_float); |
| 3800 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3801 | } else { |
| 3802 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3803 | if (is_float) { |
| 3804 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3805 | codegen_->Move(stack_temp, source); |
| 3806 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3807 | } else { |
| 3808 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3809 | codegen_->Move(stack_temp, source); |
| 3810 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3811 | } |
| 3812 | } |
| 3813 | } |
| 3814 | |
| 3815 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3816 | DataType::Type type = rem->GetResultType(); |
| 3817 | bool is_float = type == DataType::Type::kFloat32; |
| 3818 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3819 | LocationSummary* locations = rem->GetLocations(); |
| 3820 | Location first = locations->InAt(0); |
| 3821 | Location second = locations->InAt(1); |
| 3822 | Location out = locations->Out(); |
| 3823 | |
| 3824 | // Create stack space for 2 elements. |
| 3825 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3826 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3827 | |
| 3828 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3829 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3830 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3831 | |
| 3832 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3833 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3834 | __ Bind(&retry); |
| 3835 | __ fprem(); |
| 3836 | |
| 3837 | // Move FP status to AX. |
| 3838 | __ fstsw(); |
| 3839 | |
| 3840 | // And see if the argument reduction is complete. This is signaled by the |
| 3841 | // C2 FPU flag bit set to 0. |
| 3842 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3843 | __ j(kNotEqual, &retry); |
| 3844 | |
| 3845 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3846 | // Store FP top of stack to real stack. |
| 3847 | if (is_float) { |
| 3848 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3849 | } else { |
| 3850 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3851 | } |
| 3852 | |
| 3853 | // Pop the 2 items from the FP stack. |
| 3854 | __ fucompp(); |
| 3855 | |
| 3856 | // Load the value from the stack into an XMM register. |
| 3857 | DCHECK(out.IsFpuRegister()) << out; |
| 3858 | if (is_float) { |
| 3859 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3860 | } else { |
| 3861 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3862 | } |
| 3863 | |
| 3864 | // And remove the temporary stack space we allocated. |
| 3865 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3866 | } |
| 3867 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3868 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3869 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3870 | |
| 3871 | LocationSummary* locations = instruction->GetLocations(); |
| 3872 | Location second = locations->InAt(1); |
| 3873 | DCHECK(second.IsConstant()); |
| 3874 | |
| 3875 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3876 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3877 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3878 | |
| 3879 | DCHECK(imm == 1 || imm == -1); |
| 3880 | |
| 3881 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3882 | case DataType::Type::kInt32: { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3883 | if (instruction->IsRem()) { |
| 3884 | __ xorl(output_register, output_register); |
| 3885 | } else { |
| 3886 | __ movl(output_register, input_register); |
| 3887 | if (imm == -1) { |
| 3888 | __ negl(output_register); |
| 3889 | } |
| 3890 | } |
| 3891 | break; |
| 3892 | } |
| 3893 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3894 | case DataType::Type::kInt64: { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3895 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3896 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3897 | } else { |
| 3898 | __ movq(output_register, input_register); |
| 3899 | if (imm == -1) { |
| 3900 | __ negq(output_register); |
| 3901 | } |
| 3902 | } |
| 3903 | break; |
| 3904 | } |
| 3905 | |
| 3906 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3907 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3908 | } |
| 3909 | } |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3910 | void InstructionCodeGeneratorX86_64::RemByPowerOfTwo(HRem* instruction) { |
| 3911 | LocationSummary* locations = instruction->GetLocations(); |
| 3912 | Location second = locations->InAt(1); |
| 3913 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3914 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3915 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3916 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3917 | uint64_t abs_imm = AbsOrMin(imm); |
| 3918 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3919 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3920 | NearLabel done; |
| 3921 | __ movl(out, numerator); |
| 3922 | __ andl(out, Immediate(abs_imm-1)); |
| 3923 | __ j(Condition::kZero, &done); |
| 3924 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 3925 | __ testl(numerator, numerator); |
| 3926 | __ cmov(Condition::kLess, out, tmp, false); |
| 3927 | __ Bind(&done); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3928 | |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3929 | } else { |
| 3930 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3931 | codegen_->Load64BitValue(tmp, abs_imm - 1); |
| 3932 | NearLabel done; |
| 3933 | |
| 3934 | __ movq(out, numerator); |
| 3935 | __ andq(out, tmp); |
| 3936 | __ j(Condition::kZero, &done); |
| 3937 | __ movq(tmp, numerator); |
| 3938 | __ sarq(tmp, Immediate(63)); |
| 3939 | __ shlq(tmp, Immediate(WhichPowerOf2(abs_imm))); |
| 3940 | __ orq(out, tmp); |
| 3941 | __ Bind(&done); |
| 3942 | } |
| 3943 | } |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3944 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3945 | LocationSummary* locations = instruction->GetLocations(); |
| 3946 | Location second = locations->InAt(1); |
| 3947 | |
| 3948 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3949 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3950 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3951 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3952 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3953 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3954 | |
| 3955 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3956 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3957 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 3958 | // When denominator is equal to 2, we can add signed bit and numerator to tmp. |
| 3959 | // Below we are using addl instruction instead of cmov which give us 1 cycle benefit. |
| 3960 | if (abs_imm == 2) { |
| 3961 | __ leal(tmp, Address(numerator, 0)); |
| 3962 | __ shrl(tmp, Immediate(31)); |
| 3963 | __ addl(tmp, numerator); |
| 3964 | } else { |
| 3965 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
| 3966 | __ testl(numerator, numerator); |
| 3967 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3968 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3969 | int shift = CTZ(imm); |
| 3970 | __ sarl(tmp, Immediate(shift)); |
| 3971 | |
| 3972 | if (imm < 0) { |
| 3973 | __ negl(tmp); |
| 3974 | } |
| 3975 | |
| 3976 | __ movl(output_register, tmp); |
| 3977 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3978 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3979 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 3980 | if (abs_imm == 2) { |
| 3981 | __ movq(rdx, numerator); |
| 3982 | __ shrq(rdx, Immediate(63)); |
| 3983 | __ addq(rdx, numerator); |
| 3984 | } else { |
| 3985 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
| 3986 | __ addq(rdx, numerator); |
| 3987 | __ testq(numerator, numerator); |
| 3988 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3989 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3990 | int shift = CTZ(imm); |
| 3991 | __ sarq(rdx, Immediate(shift)); |
| 3992 | |
| 3993 | if (imm < 0) { |
| 3994 | __ negq(rdx); |
| 3995 | } |
| 3996 | |
| 3997 | __ movq(output_register, rdx); |
| 3998 | } |
| 3999 | } |
| 4000 | |
| 4001 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4002 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 4003 | |
| 4004 | LocationSummary* locations = instruction->GetLocations(); |
| 4005 | Location second = locations->InAt(1); |
| 4006 | |
| 4007 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 4008 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4009 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4010 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 4011 | : locations->Out().AsRegister<CpuRegister>(); |
| 4012 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4013 | |
| 4014 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 4015 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 4016 | if (instruction->IsDiv()) { |
| 4017 | DCHECK_EQ(RAX, out.AsRegister()); |
| 4018 | } else { |
| 4019 | DCHECK_EQ(RDX, out.AsRegister()); |
| 4020 | } |
| 4021 | |
| 4022 | int64_t magic; |
| 4023 | int shift; |
| 4024 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4025 | // TODO: can these branches be written as one? |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4026 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4027 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 4028 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4029 | CalculateMagicAndShiftForDivRem(imm, false /* is_long= */, &magic, &shift); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4030 | |
| 4031 | __ movl(numerator, eax); |
| 4032 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4033 | __ movl(eax, Immediate(magic)); |
| 4034 | __ imull(numerator); |
| 4035 | |
| 4036 | if (imm > 0 && magic < 0) { |
| 4037 | __ addl(edx, numerator); |
| 4038 | } else if (imm < 0 && magic > 0) { |
| 4039 | __ subl(edx, numerator); |
| 4040 | } |
| 4041 | |
| 4042 | if (shift != 0) { |
| 4043 | __ sarl(edx, Immediate(shift)); |
| 4044 | } |
| 4045 | |
| 4046 | __ movl(eax, edx); |
| 4047 | __ shrl(edx, Immediate(31)); |
| 4048 | __ addl(edx, eax); |
| 4049 | |
| 4050 | if (instruction->IsRem()) { |
| 4051 | __ movl(eax, numerator); |
| 4052 | __ imull(edx, Immediate(imm)); |
| 4053 | __ subl(eax, edx); |
| 4054 | __ movl(edx, eax); |
| 4055 | } else { |
| 4056 | __ movl(eax, edx); |
| 4057 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4058 | } else { |
| 4059 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 4060 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4061 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4062 | |
| 4063 | CpuRegister rax = eax; |
| 4064 | CpuRegister rdx = edx; |
| 4065 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4066 | CalculateMagicAndShiftForDivRem(imm, true /* is_long= */, &magic, &shift); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4067 | |
| 4068 | // Save the numerator. |
| 4069 | __ movq(numerator, rax); |
| 4070 | |
| 4071 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4072 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4073 | |
| 4074 | // RDX:RAX = magic * numerator |
| 4075 | __ imulq(numerator); |
| 4076 | |
| 4077 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4078 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4079 | __ addq(rdx, numerator); |
| 4080 | } else if (imm < 0 && magic > 0) { |
| 4081 | // RDX -= numerator |
| 4082 | __ subq(rdx, numerator); |
| 4083 | } |
| 4084 | |
| 4085 | // Shift if needed. |
| 4086 | if (shift != 0) { |
| 4087 | __ sarq(rdx, Immediate(shift)); |
| 4088 | } |
| 4089 | |
| 4090 | // RDX += 1 if RDX < 0 |
| 4091 | __ movq(rax, rdx); |
| 4092 | __ shrq(rdx, Immediate(63)); |
| 4093 | __ addq(rdx, rax); |
| 4094 | |
| 4095 | if (instruction->IsRem()) { |
| 4096 | __ movq(rax, numerator); |
| 4097 | |
| 4098 | if (IsInt<32>(imm)) { |
| 4099 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 4100 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4101 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | __ subq(rax, rdx); |
| 4105 | __ movq(rdx, rax); |
| 4106 | } else { |
| 4107 | __ movq(rax, rdx); |
| 4108 | } |
| 4109 | } |
| 4110 | } |
| 4111 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4112 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 4113 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4114 | DataType::Type type = instruction->GetResultType(); |
| 4115 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4116 | |
| 4117 | bool is_div = instruction->IsDiv(); |
| 4118 | LocationSummary* locations = instruction->GetLocations(); |
| 4119 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4120 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4121 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4122 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4123 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4124 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4125 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4126 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4127 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4128 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4129 | if (imm == 0) { |
| 4130 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4131 | } else if (imm == 1 || imm == -1) { |
| 4132 | DivRemOneOrMinusOne(instruction); |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 4133 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4134 | if (is_div) { |
| 4135 | DivByPowerOfTwo(instruction->AsDiv()); |
| 4136 | } else { |
| 4137 | RemByPowerOfTwo(instruction->AsRem()); |
| 4138 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4139 | } else { |
| 4140 | DCHECK(imm <= -2 || imm >= 2); |
| 4141 | GenerateDivRemWithAnyConstant(instruction); |
| 4142 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4143 | } else { |
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()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 4146 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4147 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4148 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4149 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4150 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 4151 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 4152 | // 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] | 4153 | if (type == DataType::Type::kInt32) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4154 | __ cmpl(second_reg, Immediate(-1)); |
| 4155 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4156 | // edx:eax <- sign-extended of eax |
| 4157 | __ cdq(); |
| 4158 | // eax = quotient, edx = remainder |
| 4159 | __ idivl(second_reg); |
| 4160 | } else { |
| 4161 | __ cmpq(second_reg, Immediate(-1)); |
| 4162 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4163 | // rdx:rax <- sign-extended of rax |
| 4164 | __ cqo(); |
| 4165 | // rax = quotient, rdx = remainder |
| 4166 | __ idivq(second_reg); |
| 4167 | } |
| 4168 | __ Bind(slow_path->GetExitLabel()); |
| 4169 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4170 | } |
| 4171 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4172 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 4173 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4174 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4175 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4176 | case DataType::Type::kInt32: |
| 4177 | case DataType::Type::kInt64: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4178 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4179 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4180 | locations->SetOut(Location::SameAsFirstInput()); |
| 4181 | // Intel uses edx:eax as the dividend. |
| 4182 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4183 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 4184 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 4185 | // output and request another temp. |
| 4186 | if (div->InputAt(1)->IsConstant()) { |
| 4187 | locations->AddTemp(Location::RequiresRegister()); |
| 4188 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4189 | break; |
| 4190 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4191 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4192 | case DataType::Type::kFloat32: |
| 4193 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4194 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4195 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4196 | locations->SetOut(Location::SameAsFirstInput()); |
| 4197 | break; |
| 4198 | } |
| 4199 | |
| 4200 | default: |
| 4201 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4202 | } |
| 4203 | } |
| 4204 | |
| 4205 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 4206 | LocationSummary* locations = div->GetLocations(); |
| 4207 | Location first = locations->InAt(0); |
| 4208 | Location second = locations->InAt(1); |
| 4209 | DCHECK(first.Equals(locations->Out())); |
| 4210 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4211 | DataType::Type type = div->GetResultType(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4212 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4213 | case DataType::Type::kInt32: |
| 4214 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4215 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4216 | break; |
| 4217 | } |
| 4218 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4219 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4220 | if (second.IsFpuRegister()) { |
| 4221 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 4222 | } else if (second.IsConstant()) { |
| 4223 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4224 | codegen_->LiteralFloatAddress( |
| 4225 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4226 | } else { |
| 4227 | DCHECK(second.IsStackSlot()); |
| 4228 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 4229 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 4230 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4231 | break; |
| 4232 | } |
| 4233 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4234 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4235 | if (second.IsFpuRegister()) { |
| 4236 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 4237 | } else if (second.IsConstant()) { |
| 4238 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4239 | codegen_->LiteralDoubleAddress( |
| 4240 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4241 | } else { |
| 4242 | DCHECK(second.IsDoubleStackSlot()); |
| 4243 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 4244 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 4245 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4246 | break; |
| 4247 | } |
| 4248 | |
| 4249 | default: |
| 4250 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4251 | } |
| 4252 | } |
| 4253 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4254 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4255 | DataType::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4256 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4257 | new (GetGraph()->GetAllocator()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4258 | |
| 4259 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4260 | case DataType::Type::kInt32: |
| 4261 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4262 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4263 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4264 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 4265 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4266 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 4267 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 4268 | // output and request another temp. |
| 4269 | if (rem->InputAt(1)->IsConstant()) { |
| 4270 | locations->AddTemp(Location::RequiresRegister()); |
| 4271 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4272 | break; |
| 4273 | } |
| 4274 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4275 | case DataType::Type::kFloat32: |
| 4276 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4277 | locations->SetInAt(0, Location::Any()); |
| 4278 | locations->SetInAt(1, Location::Any()); |
| 4279 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4280 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4281 | break; |
| 4282 | } |
| 4283 | |
| 4284 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4285 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4286 | } |
| 4287 | } |
| 4288 | |
| 4289 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4290 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4291 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4292 | case DataType::Type::kInt32: |
| 4293 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4294 | GenerateDivRemIntegral(rem); |
| 4295 | break; |
| 4296 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4297 | case DataType::Type::kFloat32: |
| 4298 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4299 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4300 | break; |
| 4301 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4302 | default: |
| 4303 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 4304 | } |
| 4305 | } |
| 4306 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4307 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4308 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4309 | switch (minmax->GetResultType()) { |
| 4310 | case DataType::Type::kInt32: |
| 4311 | case DataType::Type::kInt64: |
| 4312 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4313 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4314 | locations->SetOut(Location::SameAsFirstInput()); |
| 4315 | break; |
| 4316 | case DataType::Type::kFloat32: |
| 4317 | case DataType::Type::kFloat64: |
| 4318 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4319 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4320 | // The following is sub-optimal, but all we can do for now. It would be fine to also accept |
| 4321 | // the second input to be the output (we can simply swap inputs). |
| 4322 | locations->SetOut(Location::SameAsFirstInput()); |
| 4323 | break; |
| 4324 | default: |
| 4325 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4326 | } |
| 4327 | } |
| 4328 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4329 | void InstructionCodeGeneratorX86_64::GenerateMinMaxInt(LocationSummary* locations, |
| 4330 | bool is_min, |
| 4331 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4332 | Location op1_loc = locations->InAt(0); |
| 4333 | Location op2_loc = locations->InAt(1); |
| 4334 | |
| 4335 | // Shortcut for same input locations. |
| 4336 | if (op1_loc.Equals(op2_loc)) { |
| 4337 | // Can return immediately, as op1_loc == out_loc. |
| 4338 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 4339 | // a copy here. |
| 4340 | DCHECK(locations->Out().Equals(op1_loc)); |
| 4341 | return; |
| 4342 | } |
| 4343 | |
| 4344 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4345 | CpuRegister op2 = op2_loc.AsRegister<CpuRegister>(); |
| 4346 | |
| 4347 | // (out := op1) |
| 4348 | // out <=? op2 |
| 4349 | // if out is min jmp done |
| 4350 | // out := op2 |
| 4351 | // done: |
| 4352 | |
| 4353 | if (type == DataType::Type::kInt64) { |
| 4354 | __ cmpq(out, op2); |
| 4355 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ true); |
| 4356 | } else { |
| 4357 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 4358 | __ cmpl(out, op2); |
| 4359 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ false); |
| 4360 | } |
| 4361 | } |
| 4362 | |
| 4363 | void InstructionCodeGeneratorX86_64::GenerateMinMaxFP(LocationSummary* locations, |
| 4364 | bool is_min, |
| 4365 | DataType::Type type) { |
| 4366 | Location op1_loc = locations->InAt(0); |
| 4367 | Location op2_loc = locations->InAt(1); |
| 4368 | Location out_loc = locations->Out(); |
| 4369 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4370 | |
| 4371 | // Shortcut for same input locations. |
| 4372 | if (op1_loc.Equals(op2_loc)) { |
| 4373 | DCHECK(out_loc.Equals(op1_loc)); |
| 4374 | return; |
| 4375 | } |
| 4376 | |
| 4377 | // (out := op1) |
| 4378 | // out <=? op2 |
| 4379 | // if Nan jmp Nan_label |
| 4380 | // if out is min jmp done |
| 4381 | // if op2 is min jmp op2_label |
| 4382 | // handle -0/+0 |
| 4383 | // jmp done |
| 4384 | // Nan_label: |
| 4385 | // out := NaN |
| 4386 | // op2_label: |
| 4387 | // out := op2 |
| 4388 | // done: |
| 4389 | // |
| 4390 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4391 | // |
| 4392 | // TODO: This is straight from Quick. Make NaN an out-of-line slowpath? |
| 4393 | |
| 4394 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4395 | |
| 4396 | NearLabel nan, done, op2_label; |
| 4397 | if (type == DataType::Type::kFloat64) { |
| 4398 | __ ucomisd(out, op2); |
| 4399 | } else { |
| 4400 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4401 | __ ucomiss(out, op2); |
| 4402 | } |
| 4403 | |
| 4404 | __ j(Condition::kParityEven, &nan); |
| 4405 | |
| 4406 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4407 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4408 | |
| 4409 | // Handle 0.0/-0.0. |
| 4410 | if (is_min) { |
| 4411 | if (type == DataType::Type::kFloat64) { |
| 4412 | __ orpd(out, op2); |
| 4413 | } else { |
| 4414 | __ orps(out, op2); |
| 4415 | } |
| 4416 | } else { |
| 4417 | if (type == DataType::Type::kFloat64) { |
| 4418 | __ andpd(out, op2); |
| 4419 | } else { |
| 4420 | __ andps(out, op2); |
| 4421 | } |
| 4422 | } |
| 4423 | __ jmp(&done); |
| 4424 | |
| 4425 | // NaN handling. |
| 4426 | __ Bind(&nan); |
| 4427 | if (type == DataType::Type::kFloat64) { |
| 4428 | __ movsd(out, codegen_->LiteralInt64Address(INT64_C(0x7FF8000000000000))); |
| 4429 | } else { |
| 4430 | __ movss(out, codegen_->LiteralInt32Address(INT32_C(0x7FC00000))); |
| 4431 | } |
| 4432 | __ jmp(&done); |
| 4433 | |
| 4434 | // out := op2; |
| 4435 | __ Bind(&op2_label); |
| 4436 | if (type == DataType::Type::kFloat64) { |
| 4437 | __ movsd(out, op2); |
| 4438 | } else { |
| 4439 | __ movss(out, op2); |
| 4440 | } |
| 4441 | |
| 4442 | // Done. |
| 4443 | __ Bind(&done); |
| 4444 | } |
| 4445 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4446 | void InstructionCodeGeneratorX86_64::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4447 | DataType::Type type = minmax->GetResultType(); |
| 4448 | switch (type) { |
| 4449 | case DataType::Type::kInt32: |
| 4450 | case DataType::Type::kInt64: |
| 4451 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4452 | break; |
| 4453 | case DataType::Type::kFloat32: |
| 4454 | case DataType::Type::kFloat64: |
| 4455 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4456 | break; |
| 4457 | default: |
| 4458 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4459 | } |
| 4460 | } |
| 4461 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4462 | void LocationsBuilderX86_64::VisitMin(HMin* min) { |
| 4463 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4464 | } |
| 4465 | |
| 4466 | void InstructionCodeGeneratorX86_64::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4467 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4468 | } |
| 4469 | |
| 4470 | void LocationsBuilderX86_64::VisitMax(HMax* max) { |
| 4471 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4472 | } |
| 4473 | |
| 4474 | void InstructionCodeGeneratorX86_64::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4475 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4476 | } |
| 4477 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4478 | void LocationsBuilderX86_64::VisitAbs(HAbs* abs) { |
| 4479 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4480 | switch (abs->GetResultType()) { |
| 4481 | case DataType::Type::kInt32: |
| 4482 | case DataType::Type::kInt64: |
| 4483 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4484 | locations->SetOut(Location::SameAsFirstInput()); |
| 4485 | locations->AddTemp(Location::RequiresRegister()); |
| 4486 | break; |
| 4487 | case DataType::Type::kFloat32: |
| 4488 | case DataType::Type::kFloat64: |
| 4489 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4490 | locations->SetOut(Location::SameAsFirstInput()); |
| 4491 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4492 | break; |
| 4493 | default: |
| 4494 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4495 | } |
| 4496 | } |
| 4497 | |
| 4498 | void InstructionCodeGeneratorX86_64::VisitAbs(HAbs* abs) { |
| 4499 | LocationSummary* locations = abs->GetLocations(); |
| 4500 | switch (abs->GetResultType()) { |
| 4501 | case DataType::Type::kInt32: { |
| 4502 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4503 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4504 | // Create mask. |
| 4505 | __ movl(mask, out); |
| 4506 | __ sarl(mask, Immediate(31)); |
| 4507 | // Add mask. |
| 4508 | __ addl(out, mask); |
| 4509 | __ xorl(out, mask); |
| 4510 | break; |
| 4511 | } |
| 4512 | case DataType::Type::kInt64: { |
| 4513 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4514 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4515 | // Create mask. |
| 4516 | __ movq(mask, out); |
| 4517 | __ sarq(mask, Immediate(63)); |
| 4518 | // Add mask. |
| 4519 | __ addq(out, mask); |
| 4520 | __ xorq(out, mask); |
| 4521 | break; |
| 4522 | } |
| 4523 | case DataType::Type::kFloat32: { |
| 4524 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4525 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4526 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x7FFFFFFF))); |
| 4527 | __ andps(out, mask); |
| 4528 | break; |
| 4529 | } |
| 4530 | case DataType::Type::kFloat64: { |
| 4531 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4532 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4533 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x7FFFFFFFFFFFFFFF))); |
| 4534 | __ andpd(out, mask); |
| 4535 | break; |
| 4536 | } |
| 4537 | default: |
| 4538 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4539 | } |
| 4540 | } |
| 4541 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4542 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4543 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4544 | locations->SetInAt(0, Location::Any()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4545 | } |
| 4546 | |
| 4547 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4548 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4549 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86_64(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4550 | codegen_->AddSlowPath(slow_path); |
| 4551 | |
| 4552 | LocationSummary* locations = instruction->GetLocations(); |
| 4553 | Location value = locations->InAt(0); |
| 4554 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4555 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4556 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4557 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4558 | case DataType::Type::kInt8: |
| 4559 | case DataType::Type::kUint16: |
| 4560 | case DataType::Type::kInt16: |
| 4561 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4562 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4563 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4564 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4565 | } else if (value.IsStackSlot()) { |
| 4566 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4567 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4568 | } else { |
| 4569 | DCHECK(value.IsConstant()) << value; |
| 4570 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4571 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4572 | } |
| 4573 | } |
| 4574 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4575 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4576 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4577 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4578 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4579 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4580 | } else if (value.IsDoubleStackSlot()) { |
| 4581 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4582 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4583 | } else { |
| 4584 | DCHECK(value.IsConstant()) << value; |
| 4585 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4586 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4587 | } |
| 4588 | } |
| 4589 | break; |
| 4590 | } |
| 4591 | default: |
| 4592 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4593 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4594 | } |
| 4595 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4596 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 4597 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4598 | |
| 4599 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4600 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4601 | |
| 4602 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4603 | case DataType::Type::kInt32: |
| 4604 | case DataType::Type::kInt64: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4605 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4606 | // The shift count needs to be in CL. |
| 4607 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 4608 | locations->SetOut(Location::SameAsFirstInput()); |
| 4609 | break; |
| 4610 | } |
| 4611 | default: |
| 4612 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4613 | } |
| 4614 | } |
| 4615 | |
| 4616 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 4617 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4618 | |
| 4619 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4620 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4621 | Location second = locations->InAt(1); |
| 4622 | |
| 4623 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4624 | case DataType::Type::kInt32: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4625 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4626 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4627 | if (op->IsShl()) { |
| 4628 | __ shll(first_reg, second_reg); |
| 4629 | } else if (op->IsShr()) { |
| 4630 | __ sarl(first_reg, second_reg); |
| 4631 | } else { |
| 4632 | __ shrl(first_reg, second_reg); |
| 4633 | } |
| 4634 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4635 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4636 | if (op->IsShl()) { |
| 4637 | __ shll(first_reg, imm); |
| 4638 | } else if (op->IsShr()) { |
| 4639 | __ sarl(first_reg, imm); |
| 4640 | } else { |
| 4641 | __ shrl(first_reg, imm); |
| 4642 | } |
| 4643 | } |
| 4644 | break; |
| 4645 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4646 | case DataType::Type::kInt64: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4647 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4648 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4649 | if (op->IsShl()) { |
| 4650 | __ shlq(first_reg, second_reg); |
| 4651 | } else if (op->IsShr()) { |
| 4652 | __ sarq(first_reg, second_reg); |
| 4653 | } else { |
| 4654 | __ shrq(first_reg, second_reg); |
| 4655 | } |
| 4656 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4657 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4658 | if (op->IsShl()) { |
| 4659 | __ shlq(first_reg, imm); |
| 4660 | } else if (op->IsShr()) { |
| 4661 | __ sarq(first_reg, imm); |
| 4662 | } else { |
| 4663 | __ shrq(first_reg, imm); |
| 4664 | } |
| 4665 | } |
| 4666 | break; |
| 4667 | } |
| 4668 | default: |
| 4669 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4670 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4671 | } |
| 4672 | } |
| 4673 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4674 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 4675 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4676 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4677 | |
| 4678 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4679 | case DataType::Type::kInt32: |
| 4680 | case DataType::Type::kInt64: { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4681 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4682 | // The shift count needs to be in CL (unless it is a constant). |
| 4683 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 4684 | locations->SetOut(Location::SameAsFirstInput()); |
| 4685 | break; |
| 4686 | } |
| 4687 | default: |
| 4688 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4689 | UNREACHABLE(); |
| 4690 | } |
| 4691 | } |
| 4692 | |
| 4693 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4694 | LocationSummary* locations = ror->GetLocations(); |
| 4695 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4696 | Location second = locations->InAt(1); |
| 4697 | |
| 4698 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4699 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4700 | if (second.IsRegister()) { |
| 4701 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4702 | __ rorl(first_reg, second_reg); |
| 4703 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4704 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4705 | __ rorl(first_reg, imm); |
| 4706 | } |
| 4707 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4708 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4709 | if (second.IsRegister()) { |
| 4710 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4711 | __ rorq(first_reg, second_reg); |
| 4712 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4713 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4714 | __ rorq(first_reg, imm); |
| 4715 | } |
| 4716 | break; |
| 4717 | default: |
| 4718 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4719 | UNREACHABLE(); |
| 4720 | } |
| 4721 | } |
| 4722 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4723 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4724 | HandleShift(shl); |
| 4725 | } |
| 4726 | |
| 4727 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4728 | HandleShift(shl); |
| 4729 | } |
| 4730 | |
| 4731 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4732 | HandleShift(shr); |
| 4733 | } |
| 4734 | |
| 4735 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4736 | HandleShift(shr); |
| 4737 | } |
| 4738 | |
| 4739 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4740 | HandleShift(ushr); |
| 4741 | } |
| 4742 | |
| 4743 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4744 | HandleShift(ushr); |
| 4745 | } |
| 4746 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4747 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4748 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4749 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4750 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4751 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4752 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4756 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4757 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4758 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4759 | } |
| 4760 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4761 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4762 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4763 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4764 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4765 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4766 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4767 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4771 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 4772 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4773 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4774 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4775 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4776 | } |
| 4777 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4778 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4779 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4780 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4781 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4782 | if (location.IsStackSlot()) { |
| 4783 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4784 | } else if (location.IsDoubleStackSlot()) { |
| 4785 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4786 | } |
| 4787 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4788 | } |
| 4789 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4790 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4791 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4792 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4793 | } |
| 4794 | |
| 4795 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4796 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4797 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4798 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4799 | } |
| 4800 | |
| 4801 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4802 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4803 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4804 | } |
| 4805 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4806 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4807 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4808 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4809 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4810 | locations->SetOut(Location::RequiresRegister()); |
| 4811 | } |
| 4812 | |
| 4813 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4814 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4815 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4816 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4817 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4818 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4819 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4820 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4821 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4822 | instruction->GetIndex(), kX86_64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4823 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4824 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4825 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4826 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4827 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4828 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4829 | } |
| 4830 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4831 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4832 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4833 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4834 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4835 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4836 | } |
| 4837 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4838 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4839 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4840 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4841 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4842 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4843 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4844 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4845 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4846 | break; |
| 4847 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4848 | case DataType::Type::kInt64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4849 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4850 | break; |
| 4851 | |
| 4852 | default: |
| 4853 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4854 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4855 | } |
| 4856 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4857 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4858 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4859 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4860 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4861 | locations->SetOut(Location::SameAsFirstInput()); |
| 4862 | } |
| 4863 | |
| 4864 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4865 | LocationSummary* locations = bool_not->GetLocations(); |
| 4866 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4867 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4868 | Location out = locations->Out(); |
| 4869 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4870 | } |
| 4871 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4872 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4873 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4874 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4875 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4876 | locations->SetInAt(i, Location::Any()); |
| 4877 | } |
| 4878 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4879 | } |
| 4880 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4881 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4882 | LOG(FATAL) << "Unimplemented"; |
| 4883 | } |
| 4884 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4885 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4886 | /* |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4887 | * 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] | 4888 | * 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] | 4889 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4890 | */ |
| 4891 | switch (kind) { |
| 4892 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4893 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4894 | break; |
| 4895 | } |
| 4896 | case MemBarrierKind::kAnyStore: |
| 4897 | case MemBarrierKind::kLoadAny: |
| 4898 | case MemBarrierKind::kStoreStore: { |
| 4899 | // nop |
| 4900 | break; |
| 4901 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4902 | case MemBarrierKind::kNTStoreStore: |
| 4903 | // Non-Temporal Store/Store needs an explicit fence. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4904 | MemoryFence(/* non-temporal= */ true); |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4905 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4906 | } |
| 4907 | } |
| 4908 | |
| 4909 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4910 | DCHECK(instruction->IsInstanceFieldGet() || |
| 4911 | instruction->IsStaticFieldGet() || |
| 4912 | instruction->IsPredicatedInstanceFieldGet()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4913 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4914 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4915 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4916 | bool is_predicated = instruction->IsPredicatedInstanceFieldGet(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4917 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4918 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4919 | object_field_get_with_read_barrier |
| 4920 | ? LocationSummary::kCallOnSlowPath |
| 4921 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4922 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4923 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4924 | } |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4925 | // receiver_input |
| 4926 | locations->SetInAt(is_predicated ? 1 : 0, Location::RequiresRegister()); |
| 4927 | if (is_predicated) { |
| 4928 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| 4929 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4930 | } else { |
| 4931 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4932 | } |
| 4933 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4934 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4935 | locations->SetOut(is_predicated ? Location::SameAsFirstInput() |
| 4936 | : Location::RequiresFpuRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4937 | } else { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4938 | // The output overlaps for an object field get when read barriers are |
| 4939 | // enabled: we do not want the move to overwrite the object's location, as |
| 4940 | // we need it to emit the read barrier. For predicated instructions we can |
| 4941 | // always overlap since the output is SameAsFirst and the default value. |
| 4942 | locations->SetOut(is_predicated ? Location::SameAsFirstInput() : Location::RequiresRegister(), |
| 4943 | object_field_get_with_read_barrier || is_predicated |
| 4944 | ? Location::kOutputOverlap |
| 4945 | : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4946 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4947 | } |
| 4948 | |
| 4949 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4950 | const FieldInfo& field_info) { |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4951 | DCHECK(instruction->IsInstanceFieldGet() || |
| 4952 | instruction->IsStaticFieldGet() || |
| 4953 | instruction->IsPredicatedInstanceFieldGet()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4954 | |
| 4955 | LocationSummary* locations = instruction->GetLocations(); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 4956 | Location base_loc = locations->InAt(instruction->IsPredicatedInstanceFieldGet() ? 1 : 0); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4957 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4958 | Location out = locations->Out(); |
| 4959 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4960 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4961 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4962 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4963 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4964 | if (load_type == DataType::Type::kReference) { |
Ulya Trafimovich | 161911c | 2021-06-01 15:47:28 +0100 | [diff] [blame] | 4965 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4966 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4967 | // Note that a potential implicit null check is handled in this |
| 4968 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
| 4969 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4970 | instruction, out, base, offset, /* needs_null_check= */ true); |
| 4971 | if (is_volatile) { |
| 4972 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4973 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4974 | } else { |
Ulya Trafimovich | 161911c | 2021-06-01 15:47:28 +0100 | [diff] [blame] | 4975 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4976 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4977 | if (is_volatile) { |
| 4978 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4979 | } |
| 4980 | // If read barriers are enabled, emit read barriers other than |
| 4981 | // Baker's using a slow path (and also unpoison the loaded |
| 4982 | // reference, if heap poisoning is enabled). |
| 4983 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4984 | } |
| 4985 | } else { |
| 4986 | codegen_->LoadFromMemoryNoReference(load_type, out, Address(base, offset)); |
| 4987 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4988 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4989 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4990 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4991 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4992 | } |
| 4993 | |
| 4994 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4995 | const FieldInfo& field_info) { |
| 4996 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4997 | |
| 4998 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4999 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5000 | DataType::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5001 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5002 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5003 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5004 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5005 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5006 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5007 | if (is_volatile) { |
| 5008 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5009 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 5010 | } else { |
| 5011 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5012 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5013 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5014 | if (is_volatile) { |
| 5015 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5016 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 5017 | } else { |
| 5018 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5019 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5020 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5021 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 5022 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5023 | locations->AddTemp(Location::RequiresRegister()); |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5024 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5025 | } else if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5026 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5027 | locations->AddTemp(Location::RequiresRegister()); |
| 5028 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5029 | } |
| 5030 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5031 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5032 | uint32_t value_index, |
| 5033 | uint32_t extra_temp_index, |
| 5034 | DataType::Type field_type, |
| 5035 | Address field_addr, |
| 5036 | CpuRegister base, |
| 5037 | bool is_volatile, |
Ulya Trafimovich | 30bb6af | 2021-06-15 17:34:51 +0100 | [diff] [blame] | 5038 | bool is_atomic, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5039 | bool value_can_be_null) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5040 | LocationSummary* locations = instruction->GetLocations(); |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5041 | Location value = locations->InAt(value_index); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5042 | |
| 5043 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5044 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5045 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5046 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5047 | bool maybe_record_implicit_null_check_done = false; |
| 5048 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5049 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5050 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5051 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5052 | case DataType::Type::kInt8: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5053 | if (value.IsConstant()) { |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5054 | __ movb(field_addr, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5055 | } else { |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5056 | __ movb(field_addr, value.AsRegister<CpuRegister>()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5057 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5058 | break; |
| 5059 | } |
| 5060 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5061 | case DataType::Type::kUint16: |
| 5062 | case DataType::Type::kInt16: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5063 | if (value.IsConstant()) { |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5064 | __ movw(field_addr, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5065 | } else { |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5066 | __ movw(field_addr, value.AsRegister<CpuRegister>()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5067 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5068 | break; |
| 5069 | } |
| 5070 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5071 | case DataType::Type::kInt32: |
| 5072 | case DataType::Type::kReference: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5073 | if (value.IsConstant()) { |
| 5074 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5075 | // `field_type == DataType::Type::kReference` implies `v == 0`. |
| 5076 | DCHECK((field_type != DataType::Type::kReference) || (v == 0)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5077 | // Note: if heap poisoning is enabled, no need to poison |
| 5078 | // (negate) `v` if it is a reference, as it would be null. |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5079 | __ movl(field_addr, Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5080 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5081 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5082 | CpuRegister temp = locations->GetTemp(extra_temp_index).AsRegister<CpuRegister>(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5083 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 5084 | __ PoisonHeapReference(temp); |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5085 | __ movl(field_addr, temp); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5086 | } else { |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5087 | __ movl(field_addr, value.AsRegister<CpuRegister>()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5088 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5089 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5090 | break; |
| 5091 | } |
| 5092 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5093 | case DataType::Type::kInt64: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5094 | if (value.IsConstant()) { |
| 5095 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Ulya Trafimovich | 30bb6af | 2021-06-15 17:34:51 +0100 | [diff] [blame] | 5096 | if (is_atomic) { |
| 5097 | // Move constant into a register, then atomically store the register to memory. |
| 5098 | CpuRegister temp = locations->GetTemp(extra_temp_index).AsRegister<CpuRegister>(); |
| 5099 | __ movq(temp, Immediate(v)); |
| 5100 | __ movq(field_addr, temp); |
| 5101 | } else { |
| 5102 | codegen_->MoveInt64ToAddress(field_addr, |
| 5103 | Address::displace(field_addr, sizeof(int32_t)), |
| 5104 | v, |
| 5105 | instruction); |
| 5106 | } |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5107 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5108 | } else { |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5109 | __ movq(field_addr, value.AsRegister<CpuRegister>()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5110 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5111 | break; |
| 5112 | } |
| 5113 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5114 | case DataType::Type::kFloat32: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5115 | if (value.IsConstant()) { |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5116 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5117 | __ movl(field_addr, Immediate(v)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5118 | } else { |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5119 | __ movss(field_addr, value.AsFpuRegister<XmmRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5120 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5121 | break; |
| 5122 | } |
| 5123 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5124 | case DataType::Type::kFloat64: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5125 | if (value.IsConstant()) { |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5126 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
Ulya Trafimovich | 30bb6af | 2021-06-15 17:34:51 +0100 | [diff] [blame] | 5127 | if (is_atomic) { |
| 5128 | // Move constant into a register, then atomically store the register to memory. |
| 5129 | CpuRegister temp = locations->GetTemp(extra_temp_index).AsRegister<CpuRegister>(); |
| 5130 | __ movq(temp, Immediate(v)); |
| 5131 | __ movq(field_addr, temp); |
| 5132 | } else { |
| 5133 | codegen_->MoveInt64ToAddress(field_addr, |
| 5134 | Address::displace(field_addr, sizeof(int32_t)), |
| 5135 | v, |
| 5136 | instruction); |
| 5137 | } |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5138 | maybe_record_implicit_null_check_done = true; |
| 5139 | } else { |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5140 | __ movsd(field_addr, value.AsFpuRegister<XmmRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5141 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5142 | break; |
| 5143 | } |
| 5144 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5145 | case DataType::Type::kUint32: |
| 5146 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5147 | case DataType::Type::kVoid: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5148 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5149 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5150 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5151 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5152 | if (!maybe_record_implicit_null_check_done) { |
| 5153 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5154 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5155 | |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5156 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(value_index))) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5157 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5158 | CpuRegister card = locations->GetTemp(extra_temp_index).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5159 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5160 | } |
| 5161 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5162 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5163 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5164 | } |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
| 5168 | const FieldInfo& field_info, |
| 5169 | bool value_can_be_null) { |
| 5170 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5171 | |
| 5172 | LocationSummary* locations = instruction->GetLocations(); |
| 5173 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5174 | bool is_volatile = field_info.IsVolatile(); |
| 5175 | DataType::Type field_type = field_info.GetFieldType(); |
| 5176 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5177 | bool is_predicated = |
| 5178 | instruction->IsInstanceFieldSet() && instruction->AsInstanceFieldSet()->GetIsPredicatedSet(); |
| 5179 | |
| 5180 | NearLabel pred_is_null; |
| 5181 | if (is_predicated) { |
| 5182 | __ testl(base, base); |
| 5183 | __ j(kZero, &pred_is_null); |
| 5184 | } |
| 5185 | |
| 5186 | HandleFieldSet(instruction, |
| 5187 | /*value_index=*/ 1, |
| 5188 | /*extra_temp_index=*/ 1, |
| 5189 | field_type, |
| 5190 | Address(base, offset), |
| 5191 | base, |
| 5192 | is_volatile, |
Ulya Trafimovich | 30bb6af | 2021-06-15 17:34:51 +0100 | [diff] [blame] | 5193 | /*is_atomic=*/ false, |
Ulya Trafimovich | 6a4b299 | 2021-06-11 12:02:17 +0100 | [diff] [blame] | 5194 | value_can_be_null); |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5195 | |
| 5196 | if (is_predicated) { |
| 5197 | __ Bind(&pred_is_null); |
| 5198 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5202 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5203 | } |
| 5204 | |
| 5205 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5206 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5207 | } |
| 5208 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5209 | void LocationsBuilderX86_64::VisitPredicatedInstanceFieldGet( |
| 5210 | HPredicatedInstanceFieldGet* instruction) { |
| 5211 | HandleFieldGet(instruction); |
| 5212 | } |
| 5213 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5214 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5215 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5216 | } |
| 5217 | |
Alex Light | 3a73ffb | 2021-01-25 14:11:05 +0000 | [diff] [blame] | 5218 | void InstructionCodeGeneratorX86_64::VisitPredicatedInstanceFieldGet( |
| 5219 | HPredicatedInstanceFieldGet* instruction) { |
| 5220 | NearLabel finish; |
| 5221 | LocationSummary* locations = instruction->GetLocations(); |
| 5222 | CpuRegister target = locations->InAt(1).AsRegister<CpuRegister>(); |
| 5223 | __ testl(target, target); |
| 5224 | __ j(kZero, &finish); |
| 5225 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5226 | __ Bind(&finish); |
| 5227 | } |
| 5228 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5229 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5230 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5231 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5232 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5233 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5234 | HandleFieldGet(instruction); |
| 5235 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5236 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5237 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5238 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5239 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5240 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5241 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5242 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5243 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5244 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5245 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5246 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5247 | } |
| 5248 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 5249 | void LocationsBuilderX86_64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5250 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(RAX)); |
| 5251 | } |
| 5252 | |
| 5253 | void InstructionCodeGeneratorX86_64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5254 | __ movl(CpuRegister(RDI), Immediate(instruction->GetFormat()->GetValue())); |
| 5255 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 5256 | } |
| 5257 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5258 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 5259 | HUnresolvedInstanceFieldGet* instruction) { |
| 5260 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5261 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5262 | instruction, instruction->GetFieldType(), calling_convention); |
| 5263 | } |
| 5264 | |
| 5265 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 5266 | HUnresolvedInstanceFieldGet* instruction) { |
| 5267 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5268 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5269 | instruction->GetFieldType(), |
| 5270 | instruction->GetFieldIndex(), |
| 5271 | instruction->GetDexPc(), |
| 5272 | calling_convention); |
| 5273 | } |
| 5274 | |
| 5275 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 5276 | HUnresolvedInstanceFieldSet* instruction) { |
| 5277 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5278 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5279 | instruction, instruction->GetFieldType(), calling_convention); |
| 5280 | } |
| 5281 | |
| 5282 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 5283 | HUnresolvedInstanceFieldSet* instruction) { |
| 5284 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5285 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5286 | instruction->GetFieldType(), |
| 5287 | instruction->GetFieldIndex(), |
| 5288 | instruction->GetDexPc(), |
| 5289 | calling_convention); |
| 5290 | } |
| 5291 | |
| 5292 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 5293 | HUnresolvedStaticFieldGet* instruction) { |
| 5294 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5295 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5296 | instruction, instruction->GetFieldType(), calling_convention); |
| 5297 | } |
| 5298 | |
| 5299 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 5300 | HUnresolvedStaticFieldGet* instruction) { |
| 5301 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5302 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5303 | instruction->GetFieldType(), |
| 5304 | instruction->GetFieldIndex(), |
| 5305 | instruction->GetDexPc(), |
| 5306 | calling_convention); |
| 5307 | } |
| 5308 | |
| 5309 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 5310 | HUnresolvedStaticFieldSet* instruction) { |
| 5311 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5312 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5313 | instruction, instruction->GetFieldType(), calling_convention); |
| 5314 | } |
| 5315 | |
| 5316 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 5317 | HUnresolvedStaticFieldSet* instruction) { |
| 5318 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5319 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5320 | instruction->GetFieldType(), |
| 5321 | instruction->GetFieldIndex(), |
| 5322 | instruction->GetDexPc(), |
| 5323 | calling_convention); |
| 5324 | } |
| 5325 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5326 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5327 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5328 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5329 | ? Location::RequiresRegister() |
| 5330 | : Location::Any(); |
| 5331 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5332 | } |
| 5333 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5334 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5335 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5336 | return; |
| 5337 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5338 | LocationSummary* locations = instruction->GetLocations(); |
| 5339 | Location obj = locations->InAt(0); |
| 5340 | |
| 5341 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5342 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5343 | } |
| 5344 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5345 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5346 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5347 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5348 | |
| 5349 | LocationSummary* locations = instruction->GetLocations(); |
| 5350 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5351 | |
| 5352 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5353 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5354 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5355 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5356 | } else { |
| 5357 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5358 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5359 | __ jmp(slow_path->GetEntryLabel()); |
| 5360 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5361 | } |
| 5362 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5363 | } |
| 5364 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5365 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5366 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5367 | } |
| 5368 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5369 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5370 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5371 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5372 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5373 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5374 | object_array_get_with_read_barrier |
| 5375 | ? LocationSummary::kCallOnSlowPath |
| 5376 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5377 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5378 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5379 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5380 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5381 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5382 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5383 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5384 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5385 | // The output overlaps for an object array get when read barriers |
| 5386 | // are enabled: we do not want the move to overwrite the array's |
| 5387 | // location, as we need it to emit the read barrier. |
| 5388 | locations->SetOut( |
| 5389 | Location::RequiresRegister(), |
| 5390 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5391 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5392 | } |
| 5393 | |
| 5394 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 5395 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5396 | Location obj_loc = locations->InAt(0); |
| 5397 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5398 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5399 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5400 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5401 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5402 | DataType::Type type = instruction->GetType(); |
Ulya Trafimovich | 161911c | 2021-06-01 15:47:28 +0100 | [diff] [blame] | 5403 | if (type == DataType::Type::kReference) { |
| 5404 | static_assert( |
| 5405 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5406 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 5407 | // /* HeapReference<Object> */ out = |
| 5408 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5409 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5410 | // Note that a potential implicit null check is handled in this |
| 5411 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
| 5412 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5413 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
| 5414 | } else { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5415 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5416 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Ulya Trafimovich | 161911c | 2021-06-01 15:47:28 +0100 | [diff] [blame] | 5417 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5418 | // If read barriers are enabled, emit read barriers other than |
| 5419 | // Baker's using a slow path (and also unpoison the loaded |
| 5420 | // reference, if heap poisoning is enabled). |
| 5421 | if (index.IsConstant()) { |
| 5422 | uint32_t offset = |
| 5423 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5424 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5425 | } else { |
Ulya Trafimovich | 161911c | 2021-06-01 15:47:28 +0100 | [diff] [blame] | 5426 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5427 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5428 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5429 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5430 | } else { |
Ulya Trafimovich | 161911c | 2021-06-01 15:47:28 +0100 | [diff] [blame] | 5431 | if (type == DataType::Type::kUint16 |
| 5432 | && mirror::kUseStringCompression |
| 5433 | && instruction->IsStringCharAt()) { |
| 5434 | // Branch cases into compressed and uncompressed for each index's type. |
| 5435 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 5436 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5437 | NearLabel done, not_compressed; |
| 5438 | __ testb(Address(obj, count_offset), Immediate(1)); |
| 5439 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5440 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5441 | "Expecting 0=compressed, 1=uncompressed"); |
| 5442 | __ j(kNotZero, ¬_compressed); |
| 5443 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5444 | __ jmp(&done); |
| 5445 | __ Bind(¬_compressed); |
| 5446 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5447 | __ Bind(&done); |
| 5448 | } else { |
Ulya Trafimovich | c8451cb | 2021-06-02 17:35:16 +0100 | [diff] [blame] | 5449 | ScaleFactor scale = CodeGenerator::ScaleFactorForType(type); |
Ulya Trafimovich | 161911c | 2021-06-01 15:47:28 +0100 | [diff] [blame] | 5450 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, scale, data_offset); |
| 5451 | codegen_->LoadFromMemoryNoReference(type, out_loc, src); |
| 5452 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5453 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5454 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5455 | } |
| 5456 | |
| 5457 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5458 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5459 | |
| 5460 | bool needs_write_barrier = |
| 5461 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5462 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5463 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5464 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5465 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5466 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5467 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5468 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5469 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5470 | if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5471 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5472 | } else { |
| 5473 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5474 | } |
| 5475 | |
| 5476 | if (needs_write_barrier) { |
| 5477 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5478 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5479 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5480 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5481 | } |
| 5482 | |
| 5483 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 5484 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5485 | Location array_loc = locations->InAt(0); |
| 5486 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5487 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5488 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5489 | DataType::Type value_type = instruction->GetComponentType(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5490 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5491 | bool needs_write_barrier = |
| 5492 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5493 | |
| 5494 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5495 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5496 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5497 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5498 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5499 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5500 | if (value.IsRegister()) { |
| 5501 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5502 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5503 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5504 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5505 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5506 | break; |
| 5507 | } |
| 5508 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5509 | case DataType::Type::kUint16: |
| 5510 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5511 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5512 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5513 | if (value.IsRegister()) { |
| 5514 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5515 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5516 | DCHECK(value.IsConstant()) << value; |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5517 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5518 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5519 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5520 | break; |
| 5521 | } |
| 5522 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5523 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5524 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5525 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5526 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5527 | if (!value.IsRegister()) { |
| 5528 | // Just setting null. |
| 5529 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5530 | DCHECK(value.IsConstant()) << value; |
| 5531 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5532 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5533 | DCHECK(!needs_write_barrier); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5534 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5535 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5536 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5537 | |
| 5538 | DCHECK(needs_write_barrier); |
| 5539 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5540 | Location temp_loc = locations->GetTemp(0); |
| 5541 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5542 | |
| 5543 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 5544 | NearLabel do_store; |
| 5545 | if (can_value_be_null) { |
| 5546 | __ testl(register_value, register_value); |
| 5547 | __ j(kEqual, &do_store); |
| 5548 | } |
| 5549 | |
| 5550 | SlowPathCode* slow_path = nullptr; |
| 5551 | if (needs_type_check) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5552 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86_64(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5553 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5554 | |
| 5555 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5556 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5557 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5558 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5559 | // Note that when Baker read barriers are enabled, the type |
| 5560 | // checks are performed without read barriers. This is fine, |
| 5561 | // even in the case where a class object is in the from-space |
| 5562 | // after the flip, as a comparison involving such a type would |
| 5563 | // not produce a false positive; it may of course produce a |
| 5564 | // false negative, in which case we would take the ArraySet |
| 5565 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5566 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5567 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5568 | __ movl(temp, Address(array, class_offset)); |
| 5569 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5570 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5571 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5572 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5573 | __ movl(temp, Address(temp, component_offset)); |
| 5574 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5575 | // nor the object reference in `register_value->klass`, as |
| 5576 | // we are comparing two poisoned references. |
| 5577 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5578 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5579 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5580 | NearLabel do_put; |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5581 | __ j(kEqual, &do_put); |
| 5582 | // If heap poisoning is enabled, the `temp` reference has |
| 5583 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5584 | __ MaybeUnpoisonHeapReference(temp); |
| 5585 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5586 | // If heap poisoning is enabled, no need to unpoison the |
| 5587 | // heap reference loaded below, as it is only used for a |
| 5588 | // comparison with null. |
| 5589 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5590 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5591 | __ Bind(&do_put); |
| 5592 | } else { |
| 5593 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5594 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5595 | } |
| 5596 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5597 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 5598 | codegen_->MarkGCCard( |
| 5599 | temp, card, array, value.AsRegister<CpuRegister>(), /* value_can_be_null= */ false); |
| 5600 | |
| 5601 | if (can_value_be_null) { |
| 5602 | DCHECK(do_store.IsLinked()); |
| 5603 | __ Bind(&do_store); |
| 5604 | } |
| 5605 | |
| 5606 | Location source = value; |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5607 | if (kPoisonHeapReferences) { |
| 5608 | __ movl(temp, register_value); |
| 5609 | __ PoisonHeapReference(temp); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5610 | source = temp_loc; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5611 | } |
| 5612 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5613 | __ movl(address, source.AsRegister<CpuRegister>()); |
| 5614 | |
| 5615 | if (can_value_be_null || !needs_type_check) { |
| 5616 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5617 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5618 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5619 | if (slow_path != nullptr) { |
| 5620 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5621 | } |
| 5622 | |
| 5623 | break; |
| 5624 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5625 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5626 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5627 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5628 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5629 | if (value.IsRegister()) { |
| 5630 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 5631 | } else { |
| 5632 | DCHECK(value.IsConstant()) << value; |
| 5633 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5634 | __ movl(address, Immediate(v)); |
| 5635 | } |
| 5636 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5637 | break; |
| 5638 | } |
| 5639 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5640 | case DataType::Type::kInt64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5641 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5642 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5643 | if (value.IsRegister()) { |
| 5644 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5645 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5646 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5647 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5648 | Address address_high = |
| 5649 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5650 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5651 | } |
| 5652 | break; |
| 5653 | } |
| 5654 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5655 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5656 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5657 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5658 | if (value.IsFpuRegister()) { |
| 5659 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5660 | } else { |
| 5661 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5662 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5663 | __ movl(address, Immediate(v)); |
| 5664 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5665 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5666 | break; |
| 5667 | } |
| 5668 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5669 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5670 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5671 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5672 | if (value.IsFpuRegister()) { |
| 5673 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5674 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5675 | } else { |
| 5676 | int64_t v = |
| 5677 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5678 | Address address_high = |
| 5679 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5680 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5681 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5682 | break; |
| 5683 | } |
| 5684 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5685 | case DataType::Type::kUint32: |
| 5686 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5687 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5688 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5689 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5690 | } |
| 5691 | } |
| 5692 | |
| 5693 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5694 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5695 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5696 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5697 | if (!instruction->IsEmittedAtUseSite()) { |
| 5698 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5699 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5700 | } |
| 5701 | |
| 5702 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5703 | if (instruction->IsEmittedAtUseSite()) { |
| 5704 | return; |
| 5705 | } |
| 5706 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5707 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5708 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5709 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5710 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5711 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5712 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5713 | // Mask out most significant bit in case the array is String's array of char. |
| 5714 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5715 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5716 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5717 | } |
| 5718 | |
| 5719 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5720 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5721 | InvokeRuntimeCallingConvention calling_convention; |
| 5722 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5723 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5724 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5725 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5726 | HInstruction* length = instruction->InputAt(1); |
| 5727 | if (!length->IsEmittedAtUseSite()) { |
| 5728 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5729 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5730 | } |
| 5731 | |
| 5732 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5733 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5734 | Location index_loc = locations->InAt(0); |
| 5735 | Location length_loc = locations->InAt(1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5736 | SlowPathCode* slow_path = |
| 5737 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5738 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5739 | if (length_loc.IsConstant()) { |
| 5740 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5741 | if (index_loc.IsConstant()) { |
| 5742 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5743 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5744 | if (index < 0 || index >= length) { |
| 5745 | codegen_->AddSlowPath(slow_path); |
| 5746 | __ jmp(slow_path->GetEntryLabel()); |
| 5747 | } else { |
| 5748 | // Some optimization after BCE may have generated this, and we should not |
| 5749 | // generate a bounds check if it is a valid range. |
| 5750 | } |
| 5751 | return; |
| 5752 | } |
| 5753 | |
| 5754 | // We have to reverse the jump condition because the length is the constant. |
| 5755 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5756 | __ cmpl(index_reg, Immediate(length)); |
| 5757 | codegen_->AddSlowPath(slow_path); |
| 5758 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5759 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5760 | HInstruction* array_length = instruction->InputAt(1); |
| 5761 | if (array_length->IsEmittedAtUseSite()) { |
| 5762 | // Address the length field in the array. |
| 5763 | DCHECK(array_length->IsArrayLength()); |
| 5764 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5765 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5766 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5767 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5768 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5769 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5770 | CpuRegister length_reg = CpuRegister(TMP); |
| 5771 | __ movl(length_reg, array_len); |
| 5772 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5773 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5774 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5775 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5776 | // Checking the bound for general case: |
| 5777 | // Array of char or String's array when the compression feature off. |
| 5778 | if (index_loc.IsConstant()) { |
| 5779 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5780 | __ cmpl(array_len, Immediate(value)); |
| 5781 | } else { |
| 5782 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5783 | } |
| 5784 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5785 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5786 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5787 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5788 | } |
| 5789 | codegen_->AddSlowPath(slow_path); |
| 5790 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5791 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5792 | } |
| 5793 | |
| 5794 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5795 | CpuRegister card, |
| 5796 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5797 | CpuRegister value, |
| 5798 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5799 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5800 | if (value_can_be_null) { |
| 5801 | __ testl(value, value); |
| 5802 | __ j(kEqual, &is_null); |
| 5803 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5804 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5805 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5806 | /* no_rip= */ true)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5807 | // Calculate the offset (in the card table) of the card corresponding to |
| 5808 | // `object`. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5809 | __ movq(temp, object); |
| 5810 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5811 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5812 | // `object`'s card. |
| 5813 | // |
| 5814 | // Register `card` contains the address of the card table. Note that the card |
| 5815 | // table's base is biased during its creation so that it always starts at an |
| 5816 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5817 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5818 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5819 | // (located at `card + object >> kCardShift`). |
| 5820 | // |
| 5821 | // This dual use of the value in register `card` (1. to calculate the location |
| 5822 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5823 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5824 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5825 | if (value_can_be_null) { |
| 5826 | __ Bind(&is_null); |
| 5827 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5828 | } |
| 5829 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5830 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5831 | LOG(FATAL) << "Unimplemented"; |
| 5832 | } |
| 5833 | |
| 5834 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5835 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5836 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5837 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5838 | // The back edge will generate the suspend check. |
| 5839 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5840 | } |
| 5841 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5842 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5843 | } |
| 5844 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5845 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5846 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5847 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5848 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5849 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5850 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5851 | locations->SetCustomSlowPathCallerSaves( |
| 5852 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5856 | HBasicBlock* block = instruction->GetBlock(); |
| 5857 | if (block->GetLoopInformation() != nullptr) { |
| 5858 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5859 | // The back edge will generate the suspend check. |
| 5860 | return; |
| 5861 | } |
| 5862 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5863 | // The goto will generate the suspend check. |
| 5864 | return; |
| 5865 | } |
| 5866 | GenerateSuspendCheck(instruction, nullptr); |
| 5867 | } |
| 5868 | |
| 5869 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5870 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5871 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5872 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5873 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5874 | slow_path = |
| 5875 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86_64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5876 | instruction->SetSlowPath(slow_path); |
| 5877 | codegen_->AddSlowPath(slow_path); |
| 5878 | if (successor != nullptr) { |
| 5879 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5880 | } |
| 5881 | } else { |
| 5882 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5883 | } |
| 5884 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5885 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5886 | /* no_rip= */ true), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5887 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5888 | if (successor == nullptr) { |
| 5889 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5890 | __ Bind(slow_path->GetReturnLabel()); |
| 5891 | } else { |
| 5892 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5893 | __ jmp(slow_path->GetEntryLabel()); |
| 5894 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5895 | } |
| 5896 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5897 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5898 | return codegen_->GetAssembler(); |
| 5899 | } |
| 5900 | |
| 5901 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5902 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5903 | Location source = move->GetSource(); |
| 5904 | Location destination = move->GetDestination(); |
| 5905 | |
| 5906 | if (source.IsRegister()) { |
| 5907 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5908 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5909 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5910 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5911 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5912 | } else { |
| 5913 | DCHECK(destination.IsDoubleStackSlot()); |
| 5914 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5915 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5916 | } |
| 5917 | } else if (source.IsStackSlot()) { |
| 5918 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5919 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5920 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5921 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5922 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5923 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5924 | } else { |
| 5925 | DCHECK(destination.IsStackSlot()); |
| 5926 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5927 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5928 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5929 | } else if (source.IsDoubleStackSlot()) { |
| 5930 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5931 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5932 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5933 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5934 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5935 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5936 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5937 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5938 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5939 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5940 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5941 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5942 | if (destination.IsFpuRegister()) { |
| 5943 | __ movups(destination.AsFpuRegister<XmmRegister>(), |
| 5944 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5945 | } else { |
| 5946 | DCHECK(destination.IsSIMDStackSlot()); |
| 5947 | size_t high = kX86_64WordSize; |
| 5948 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5949 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5950 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex() + high)); |
| 5951 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex() + high), CpuRegister(TMP)); |
| 5952 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5953 | } else if (source.IsConstant()) { |
| 5954 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5955 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5956 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5957 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5958 | if (value == 0) { |
| 5959 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5960 | } else { |
| 5961 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5962 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5963 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5964 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5965 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5966 | } |
| 5967 | } else if (constant->IsLongConstant()) { |
| 5968 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5969 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5970 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5971 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5972 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5973 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5974 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5975 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5976 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5977 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5978 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5979 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5980 | } else { |
| 5981 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5982 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5983 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5984 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5985 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5986 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5987 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5988 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5989 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5990 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5991 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5992 | } else { |
| 5993 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5994 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5995 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5996 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5997 | } else if (source.IsFpuRegister()) { |
| 5998 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5999 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6000 | } else if (destination.IsStackSlot()) { |
| 6001 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6002 | source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6003 | } else if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6004 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6005 | source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6006 | } else { |
| 6007 | DCHECK(destination.IsSIMDStackSlot()); |
| 6008 | __ movups(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 6009 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6010 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6011 | } |
| 6012 | } |
| 6013 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 6014 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6015 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 6016 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 6017 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6018 | } |
| 6019 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 6020 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 6021 | __ movq(CpuRegister(TMP), reg1); |
| 6022 | __ movq(reg1, reg2); |
| 6023 | __ movq(reg2, CpuRegister(TMP)); |
| 6024 | } |
| 6025 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 6026 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 6027 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 6028 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 6029 | __ movq(reg, CpuRegister(TMP)); |
| 6030 | } |
| 6031 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6032 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 6033 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 6034 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 6035 | __ movd(reg, CpuRegister(TMP)); |
| 6036 | } |
| 6037 | |
| 6038 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 6039 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 6040 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 6041 | __ movd(reg, CpuRegister(TMP)); |
| 6042 | } |
| 6043 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6044 | void ParallelMoveResolverX86_64::Exchange128(XmmRegister reg, int mem) { |
| 6045 | size_t extra_slot = 2 * kX86_64WordSize; |
| 6046 | __ subq(CpuRegister(RSP), Immediate(extra_slot)); |
| 6047 | __ movups(Address(CpuRegister(RSP), 0), XmmRegister(reg)); |
| 6048 | ExchangeMemory64(0, mem + extra_slot, 2); |
| 6049 | __ movups(XmmRegister(reg), Address(CpuRegister(RSP), 0)); |
| 6050 | __ addq(CpuRegister(RSP), Immediate(extra_slot)); |
| 6051 | } |
| 6052 | |
| 6053 | void ParallelMoveResolverX86_64::ExchangeMemory32(int mem1, int mem2) { |
| 6054 | ScratchRegisterScope ensure_scratch( |
| 6055 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 6056 | |
| 6057 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 6058 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 6059 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 6060 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 6061 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 6062 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 6063 | CpuRegister(ensure_scratch.GetRegister())); |
| 6064 | } |
| 6065 | |
| 6066 | void ParallelMoveResolverX86_64::ExchangeMemory64(int mem1, int mem2, int num_of_qwords) { |
| 6067 | ScratchRegisterScope ensure_scratch( |
| 6068 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 6069 | |
| 6070 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 6071 | |
| 6072 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6073 | for (int i = 0; i < num_of_qwords; i++) { |
| 6074 | __ movq(CpuRegister(TMP), |
| 6075 | Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 6076 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 6077 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 6078 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), |
| 6079 | CpuRegister(TMP)); |
| 6080 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 6081 | CpuRegister(ensure_scratch.GetRegister())); |
| 6082 | stack_offset += kX86_64WordSize; |
| 6083 | } |
| 6084 | } |
| 6085 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6086 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6087 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6088 | Location source = move->GetSource(); |
| 6089 | Location destination = move->GetDestination(); |
| 6090 | |
| 6091 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 6092 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6093 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6094 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6095 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6096 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6097 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6098 | ExchangeMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 6099 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6100 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 6101 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6102 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 6103 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6104 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6105 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6106 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 6107 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 6108 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6109 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6110 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6111 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6112 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6113 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6114 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6115 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6116 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6117 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6118 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 6119 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6120 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6121 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6122 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6123 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6124 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6125 | } |
| 6126 | } |
| 6127 | |
| 6128 | |
| 6129 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 6130 | __ pushq(CpuRegister(reg)); |
| 6131 | } |
| 6132 | |
| 6133 | |
| 6134 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 6135 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6136 | } |
| 6137 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6138 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6139 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6140 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 6141 | const size_t status_byte_offset = |
| 6142 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 6143 | constexpr uint32_t shifted_visibly_initialized_value = |
| 6144 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6145 | |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 6146 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6147 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6148 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6149 | } |
| 6150 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6151 | void InstructionCodeGeneratorX86_64::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 6152 | CpuRegister temp) { |
| 6153 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 6154 | uint32_t mask = check->GetBitstringMask(); |
| 6155 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 6156 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 6157 | |
| 6158 | if (mask_bits == 16u) { |
| 6159 | // Compare the bitstring in memory. |
| 6160 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 6161 | } else { |
| 6162 | // /* uint32_t */ temp = temp->status_ |
| 6163 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 6164 | // Compare the bitstring bits using SUB. |
| 6165 | __ subl(temp, Immediate(path_to_root)); |
| 6166 | // Shift out bits that do not contribute to the comparison. |
| 6167 | __ shll(temp, Immediate(32u - mask_bits)); |
| 6168 | } |
| 6169 | } |
| 6170 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6171 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 6172 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6173 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6174 | case HLoadClass::LoadKind::kInvalid: |
| 6175 | LOG(FATAL) << "UNREACHABLE"; |
| 6176 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6177 | case HLoadClass::LoadKind::kReferrersClass: |
| 6178 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6179 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6180 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6181 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6182 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 6183 | case HLoadClass::LoadKind::kBssEntryPackage: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6184 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6185 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6186 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6187 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6188 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6189 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6190 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6191 | break; |
| 6192 | } |
| 6193 | return desired_class_load_kind; |
| 6194 | } |
| 6195 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6196 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6197 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6198 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6199 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6200 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6201 | cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6202 | Location::RegisterLocation(RAX), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6203 | Location::RegisterLocation(RAX)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6204 | return; |
| 6205 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6206 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 6207 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 6208 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6209 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6210 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6211 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6212 | ? LocationSummary::kCallOnSlowPath |
| 6213 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6214 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6215 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6216 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6217 | } |
| 6218 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6219 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6220 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6221 | } |
| 6222 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6223 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6224 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6225 | // Rely on the type resolution and/or initialization to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6226 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6227 | } else { |
| 6228 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6229 | } |
| 6230 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6231 | } |
| 6232 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6233 | Label* CodeGeneratorX86_64::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6234 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6235 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6236 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6237 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6238 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6239 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6240 | return &info->label; |
| 6241 | } |
| 6242 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6243 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6244 | // move. |
| 6245 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6246 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6247 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6248 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6249 | return; |
| 6250 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6251 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 6252 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 6253 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6254 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6255 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6256 | Location out_loc = locations->Out(); |
| 6257 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6258 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6259 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6260 | ? kWithoutReadBarrier |
| 6261 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6262 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6263 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6264 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6265 | DCHECK(!cls->CanCallRuntime()); |
| 6266 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6267 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6268 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6269 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6270 | cls, |
| 6271 | out_loc, |
| 6272 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6273 | /* fixup_label= */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6274 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6275 | break; |
| 6276 | } |
| 6277 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6278 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6279 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6280 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6281 | __ leal(out, |
| 6282 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6283 | codegen_->RecordBootImageTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6284 | break; |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6285 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6286 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6287 | __ movl(out, |
| 6288 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 6289 | codegen_->RecordBootImageRelRoPatch(CodeGenerator::GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6290 | break; |
| 6291 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6292 | case HLoadClass::LoadKind::kBssEntry: |
| 6293 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 6294 | case HLoadClass::LoadKind::kBssEntryPackage: { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6295 | Address address = Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6296 | /* no_rip= */ false); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6297 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6298 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 6299 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6300 | // No need for memory fence, thanks to the x86-64 memory model. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6301 | generate_null_check = true; |
| 6302 | break; |
| 6303 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6304 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 6305 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6306 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 6307 | DCHECK_NE(address, 0u); |
| 6308 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| 6309 | break; |
| 6310 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6311 | case HLoadClass::LoadKind::kJitTableAddress: { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6312 | Address address = Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6313 | /* no_rip= */ true); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6314 | Label* fixup_label = |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6315 | codegen_->NewJitRootClassPatch(cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6316 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6317 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6318 | break; |
| 6319 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6320 | default: |
| 6321 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 6322 | UNREACHABLE(); |
| 6323 | } |
| 6324 | |
| 6325 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6326 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6327 | SlowPathCode* slow_path = |
| 6328 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6329 | codegen_->AddSlowPath(slow_path); |
| 6330 | if (generate_null_check) { |
| 6331 | __ testl(out, out); |
| 6332 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6333 | } |
| 6334 | if (cls->MustGenerateClinitCheck()) { |
| 6335 | GenerateClassInitializationCheck(slow_path, out); |
| 6336 | } else { |
| 6337 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6338 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6339 | } |
| 6340 | } |
| 6341 | |
| 6342 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 6343 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6344 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6345 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6346 | if (check->HasUses()) { |
| 6347 | locations->SetOut(Location::SameAsFirstInput()); |
| 6348 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6349 | // Rely on the type initialization to save everything we need. |
| 6350 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6351 | } |
| 6352 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6353 | void LocationsBuilderX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6354 | // Custom calling convention: RAX serves as both input and output. |
| 6355 | Location location = Location::RegisterLocation(RAX); |
| 6356 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 6357 | } |
| 6358 | |
| 6359 | void InstructionCodeGeneratorX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6360 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 6361 | } |
| 6362 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6363 | void LocationsBuilderX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 6364 | // Custom calling convention: RAX serves as both input and output. |
| 6365 | Location location = Location::RegisterLocation(RAX); |
| 6366 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 6367 | } |
| 6368 | |
| 6369 | void InstructionCodeGeneratorX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 6370 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 6371 | } |
| 6372 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6373 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6374 | // We assume the class to not be null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6375 | SlowPathCode* slow_path = |
| 6376 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64(check->GetLoadClass(), check); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6377 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6378 | GenerateClassInitializationCheck(slow_path, |
| 6379 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6380 | } |
| 6381 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6382 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 6383 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6384 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6385 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6386 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6387 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6388 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6389 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6390 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6391 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6392 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6393 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6394 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6395 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6396 | } |
| 6397 | return desired_string_load_kind; |
| 6398 | } |
| 6399 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6400 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6401 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6402 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6403 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6404 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 6405 | } else { |
| 6406 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6407 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 6408 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6409 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6410 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6411 | } else { |
| 6412 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6413 | } |
| 6414 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6415 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6416 | } |
| 6417 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6418 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6419 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6420 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6421 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6422 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6423 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6424 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6425 | return &info->label; |
| 6426 | } |
| 6427 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6428 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6429 | // move. |
| 6430 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6431 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6432 | Location out_loc = locations->Out(); |
| 6433 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6434 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6435 | switch (load->GetLoadKind()) { |
| 6436 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6437 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6438 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6439 | __ leal(out, |
| 6440 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6441 | codegen_->RecordBootImageStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6442 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6443 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6444 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6445 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6446 | __ movl(out, |
| 6447 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 6448 | codegen_->RecordBootImageRelRoPatch(CodeGenerator::GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6449 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6450 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6451 | case HLoadString::LoadKind::kBssEntry: { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6452 | Address address = Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6453 | /* no_rip= */ false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6454 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 6455 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6456 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6457 | // No need for memory fence, thanks to the x86-64 memory model. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6458 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86_64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6459 | codegen_->AddSlowPath(slow_path); |
| 6460 | __ testl(out, out); |
| 6461 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6462 | __ Bind(slow_path->GetExitLabel()); |
| 6463 | return; |
| 6464 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6465 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 6466 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 6467 | DCHECK_NE(address, 0u); |
| 6468 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| 6469 | return; |
| 6470 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6471 | case HLoadString::LoadKind::kJitTableAddress: { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6472 | Address address = Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6473 | /* no_rip= */ true); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6474 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 6475 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6476 | // /* GcRoot<mirror::String> */ out = *address |
| 6477 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6478 | return; |
| 6479 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6480 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6481 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6482 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6483 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6484 | // 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] | 6485 | // Custom calling convention: RAX serves as both input and output. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6486 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6487 | codegen_->InvokeRuntime(kQuickResolveString, |
| 6488 | load, |
| 6489 | load->GetDexPc()); |
| 6490 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6491 | } |
| 6492 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6493 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6494 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6495 | /* no_rip= */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6496 | } |
| 6497 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6498 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 6499 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6500 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6501 | locations->SetOut(Location::RequiresRegister()); |
| 6502 | } |
| 6503 | |
| 6504 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6505 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 6506 | } |
| 6507 | |
| 6508 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6509 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6510 | } |
| 6511 | |
| 6512 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6513 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6514 | } |
| 6515 | |
| 6516 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6517 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6518 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6519 | InvokeRuntimeCallingConvention calling_convention; |
| 6520 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6521 | } |
| 6522 | |
| 6523 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6524 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6525 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6526 | } |
| 6527 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6528 | // Temp is used for read barrier. |
| 6529 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6530 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6531 | !kUseBakerReadBarrier && |
| 6532 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6533 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6534 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6535 | return 1; |
| 6536 | } |
| 6537 | return 0; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6538 | } |
| 6539 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6540 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 6541 | // interface pointer, the current interface is compared in memory. |
| 6542 | // The other checks have one temp for loading the object's class. |
| 6543 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6544 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6545 | return 2; |
| 6546 | } |
| 6547 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6548 | } |
| 6549 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6550 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6551 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6552 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6553 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6554 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6555 | case TypeCheckKind::kExactCheck: |
| 6556 | case TypeCheckKind::kAbstractClassCheck: |
| 6557 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6558 | case TypeCheckKind::kArrayObjectCheck: { |
| 6559 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6560 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6561 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6562 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6563 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6564 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6565 | case TypeCheckKind::kUnresolvedCheck: |
| 6566 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6567 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6568 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6569 | case TypeCheckKind::kBitstringCheck: |
| 6570 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6571 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6572 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6573 | LocationSummary* locations = |
| 6574 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6575 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6576 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6577 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6578 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6579 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6580 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6581 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6582 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 6583 | } else { |
| 6584 | locations->SetInAt(1, Location::Any()); |
| 6585 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6586 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 6587 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6588 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6589 | } |
| 6590 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6591 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6592 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6593 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6594 | Location obj_loc = locations->InAt(0); |
| 6595 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6596 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6597 | Location out_loc = locations->Out(); |
| 6598 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6599 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6600 | DCHECK_LE(num_temps, 1u); |
| 6601 | Location maybe_temp_loc = (num_temps >= 1u) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6602 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6603 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6604 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6605 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6606 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6607 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6608 | |
| 6609 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6610 | // Avoid null check if we know obj is not null. |
| 6611 | if (instruction->MustDoNullCheck()) { |
| 6612 | __ testl(obj, obj); |
| 6613 | __ j(kEqual, &zero); |
| 6614 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6615 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6616 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6617 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6618 | ReadBarrierOption read_barrier_option = |
| 6619 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6620 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6621 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6622 | out_loc, |
| 6623 | obj_loc, |
| 6624 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6625 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6626 | if (cls.IsRegister()) { |
| 6627 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6628 | } else { |
| 6629 | DCHECK(cls.IsStackSlot()) << cls; |
| 6630 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6631 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6632 | if (zero.IsLinked()) { |
| 6633 | // Classes must be equal for the instanceof to succeed. |
| 6634 | __ j(kNotEqual, &zero); |
| 6635 | __ movl(out, Immediate(1)); |
| 6636 | __ jmp(&done); |
| 6637 | } else { |
| 6638 | __ setcc(kEqual, out); |
| 6639 | // setcc only sets the low byte. |
| 6640 | __ andl(out, Immediate(1)); |
| 6641 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6642 | break; |
| 6643 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6644 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6645 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6646 | ReadBarrierOption read_barrier_option = |
| 6647 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6648 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6649 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6650 | out_loc, |
| 6651 | obj_loc, |
| 6652 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6653 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6654 | // If the class is abstract, we eagerly fetch the super class of the |
| 6655 | // object to avoid doing a comparison we know will fail. |
| 6656 | NearLabel loop, success; |
| 6657 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6658 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6659 | GenerateReferenceLoadOneRegister(instruction, |
| 6660 | out_loc, |
| 6661 | super_offset, |
| 6662 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6663 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6664 | __ testl(out, out); |
| 6665 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6666 | __ j(kEqual, &done); |
| 6667 | if (cls.IsRegister()) { |
| 6668 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6669 | } else { |
| 6670 | DCHECK(cls.IsStackSlot()) << cls; |
| 6671 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6672 | } |
| 6673 | __ j(kNotEqual, &loop); |
| 6674 | __ movl(out, Immediate(1)); |
| 6675 | if (zero.IsLinked()) { |
| 6676 | __ jmp(&done); |
| 6677 | } |
| 6678 | break; |
| 6679 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6680 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6681 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6682 | ReadBarrierOption read_barrier_option = |
| 6683 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6684 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6685 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6686 | out_loc, |
| 6687 | obj_loc, |
| 6688 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6689 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6690 | // Walk over the class hierarchy to find a match. |
| 6691 | NearLabel loop, success; |
| 6692 | __ Bind(&loop); |
| 6693 | if (cls.IsRegister()) { |
| 6694 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6695 | } else { |
| 6696 | DCHECK(cls.IsStackSlot()) << cls; |
| 6697 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6698 | } |
| 6699 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6700 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6701 | GenerateReferenceLoadOneRegister(instruction, |
| 6702 | out_loc, |
| 6703 | super_offset, |
| 6704 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6705 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6706 | __ testl(out, out); |
| 6707 | __ j(kNotEqual, &loop); |
| 6708 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6709 | __ jmp(&done); |
| 6710 | __ Bind(&success); |
| 6711 | __ movl(out, Immediate(1)); |
| 6712 | if (zero.IsLinked()) { |
| 6713 | __ jmp(&done); |
| 6714 | } |
| 6715 | break; |
| 6716 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6717 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6718 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6719 | ReadBarrierOption read_barrier_option = |
| 6720 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6721 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6722 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6723 | out_loc, |
| 6724 | obj_loc, |
| 6725 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6726 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6727 | // Do an exact check. |
| 6728 | NearLabel exact_check; |
| 6729 | if (cls.IsRegister()) { |
| 6730 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6731 | } else { |
| 6732 | DCHECK(cls.IsStackSlot()) << cls; |
| 6733 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6734 | } |
| 6735 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6736 | // 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] | 6737 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6738 | GenerateReferenceLoadOneRegister(instruction, |
| 6739 | out_loc, |
| 6740 | component_offset, |
| 6741 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6742 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6743 | __ testl(out, out); |
| 6744 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6745 | __ j(kEqual, &done); |
| 6746 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6747 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6748 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6749 | __ movl(out, Immediate(1)); |
| 6750 | __ jmp(&done); |
| 6751 | break; |
| 6752 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6753 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6754 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6755 | // No read barrier since the slow path will retry upon failure. |
| 6756 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6757 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6758 | out_loc, |
| 6759 | obj_loc, |
| 6760 | class_offset, |
| 6761 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6762 | if (cls.IsRegister()) { |
| 6763 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6764 | } else { |
| 6765 | DCHECK(cls.IsStackSlot()) << cls; |
| 6766 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6767 | } |
| 6768 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6769 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6770 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6771 | codegen_->AddSlowPath(slow_path); |
| 6772 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6773 | __ movl(out, Immediate(1)); |
| 6774 | if (zero.IsLinked()) { |
| 6775 | __ jmp(&done); |
| 6776 | } |
| 6777 | break; |
| 6778 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6779 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6780 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6781 | case TypeCheckKind::kInterfaceCheck: { |
| 6782 | // 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] | 6783 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6784 | // cases. |
| 6785 | // |
| 6786 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6787 | // entry point without resorting to a type checking slow path |
| 6788 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6789 | // require to assign fixed registers for the inputs of this |
| 6790 | // HInstanceOf instruction (following the runtime calling |
| 6791 | // convention), which might be cluttered by the potential first |
| 6792 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6793 | // |
| 6794 | // TODO: Introduce a new runtime entry point taking the object |
| 6795 | // to test (instead of its class) as argument, and let it deal |
| 6796 | // with the read barrier issues. This will let us refactor this |
| 6797 | // case of the `switch` code as it was previously (with a direct |
| 6798 | // call to the runtime not using a type checking slow path). |
| 6799 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6800 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6801 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6802 | instruction, /* is_fatal= */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6803 | codegen_->AddSlowPath(slow_path); |
| 6804 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6805 | if (zero.IsLinked()) { |
| 6806 | __ jmp(&done); |
| 6807 | } |
| 6808 | break; |
| 6809 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6810 | |
| 6811 | case TypeCheckKind::kBitstringCheck: { |
| 6812 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6813 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6814 | out_loc, |
| 6815 | obj_loc, |
| 6816 | class_offset, |
| 6817 | kWithoutReadBarrier); |
| 6818 | |
| 6819 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 6820 | if (zero.IsLinked()) { |
| 6821 | __ j(kNotEqual, &zero); |
| 6822 | __ movl(out, Immediate(1)); |
| 6823 | __ jmp(&done); |
| 6824 | } else { |
| 6825 | __ setcc(kEqual, out); |
| 6826 | // setcc only sets the low byte. |
| 6827 | __ andl(out, Immediate(1)); |
| 6828 | } |
| 6829 | break; |
| 6830 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6831 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6832 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6833 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6834 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6835 | __ xorl(out, out); |
| 6836 | } |
| 6837 | |
| 6838 | if (done.IsLinked()) { |
| 6839 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6840 | } |
| 6841 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6842 | if (slow_path != nullptr) { |
| 6843 | __ Bind(slow_path->GetExitLabel()); |
| 6844 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6845 | } |
| 6846 | |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6847 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6848 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6849 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6850 | LocationSummary* locations = |
| 6851 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6852 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6853 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6854 | // Require a register for the interface check since there is a loop that compares the class to |
| 6855 | // a memory address. |
| 6856 | locations->SetInAt(1, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6857 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6858 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6859 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6860 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6861 | } else { |
| 6862 | locations->SetInAt(1, Location::Any()); |
| 6863 | } |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6864 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathX86. |
| 6865 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6866 | } |
| 6867 | |
| 6868 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6869 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6870 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6871 | Location obj_loc = locations->InAt(0); |
| 6872 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6873 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6874 | Location temp_loc = locations->GetTemp(0); |
| 6875 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6876 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6877 | DCHECK_GE(num_temps, 1u); |
| 6878 | DCHECK_LE(num_temps, 2u); |
| 6879 | Location maybe_temp2_loc = (num_temps >= 2u) ? locations->GetTemp(1) : Location::NoLocation(); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6880 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6881 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6882 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6883 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6884 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6885 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6886 | const uint32_t object_array_data_offset = |
| 6887 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6888 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6889 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6890 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6891 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6892 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6893 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6894 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6895 | |
| 6896 | NearLabel done; |
| 6897 | // Avoid null check if we know obj is not null. |
| 6898 | if (instruction->MustDoNullCheck()) { |
| 6899 | __ testl(obj, obj); |
| 6900 | __ j(kEqual, &done); |
| 6901 | } |
| 6902 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6903 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6904 | case TypeCheckKind::kExactCheck: |
| 6905 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6906 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6907 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6908 | temp_loc, |
| 6909 | obj_loc, |
| 6910 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6911 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6912 | if (cls.IsRegister()) { |
| 6913 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6914 | } else { |
| 6915 | DCHECK(cls.IsStackSlot()) << cls; |
| 6916 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6917 | } |
| 6918 | // Jump to slow path for throwing the exception or doing a |
| 6919 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6920 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6921 | break; |
| 6922 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6923 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6924 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6925 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6926 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6927 | temp_loc, |
| 6928 | obj_loc, |
| 6929 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6930 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6931 | // If the class is abstract, we eagerly fetch the super class of the |
| 6932 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6933 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6934 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6935 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6936 | GenerateReferenceLoadOneRegister(instruction, |
| 6937 | temp_loc, |
| 6938 | super_offset, |
| 6939 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6940 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6941 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6942 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6943 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6944 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6945 | // Otherwise, compare the classes. |
| 6946 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6947 | if (cls.IsRegister()) { |
| 6948 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6949 | } else { |
| 6950 | DCHECK(cls.IsStackSlot()) << cls; |
| 6951 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6952 | } |
| 6953 | __ j(kNotEqual, &loop); |
| 6954 | break; |
| 6955 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6956 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6957 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6958 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6959 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6960 | temp_loc, |
| 6961 | obj_loc, |
| 6962 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6963 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6964 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6965 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6966 | __ Bind(&loop); |
| 6967 | if (cls.IsRegister()) { |
| 6968 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6969 | } else { |
| 6970 | DCHECK(cls.IsStackSlot()) << cls; |
| 6971 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6972 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6973 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6974 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6975 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6976 | GenerateReferenceLoadOneRegister(instruction, |
| 6977 | temp_loc, |
| 6978 | super_offset, |
| 6979 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6980 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6981 | |
| 6982 | // If the class reference currently in `temp` is not null, jump |
| 6983 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6984 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6985 | __ j(kNotZero, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6986 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6987 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6988 | break; |
| 6989 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6990 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6991 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6992 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6993 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6994 | temp_loc, |
| 6995 | obj_loc, |
| 6996 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6997 | kWithoutReadBarrier); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6998 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6999 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7000 | if (cls.IsRegister()) { |
| 7001 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 7002 | } else { |
| 7003 | DCHECK(cls.IsStackSlot()) << cls; |
| 7004 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 7005 | } |
| 7006 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7007 | |
| 7008 | // 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] | 7009 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7010 | GenerateReferenceLoadOneRegister(instruction, |
| 7011 | temp_loc, |
| 7012 | component_offset, |
| 7013 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7014 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7015 | |
| 7016 | // If the component type is not null (i.e. the object is indeed |
| 7017 | // an array), jump to label `check_non_primitive_component_type` |
| 7018 | // to further check that this component type is not a primitive |
| 7019 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7020 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7021 | // Otherwise, jump to the slow path to throw the exception. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7022 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7023 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7024 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7025 | break; |
| 7026 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7027 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7028 | case TypeCheckKind::kUnresolvedCheck: { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 7029 | // 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] | 7030 | // |
| 7031 | // We cannot directly call the CheckCast runtime entry point |
| 7032 | // without resorting to a type checking slow path here (i.e. by |
| 7033 | // calling InvokeRuntime directly), as it would require to |
| 7034 | // assign fixed registers for the inputs of this HInstanceOf |
| 7035 | // instruction (following the runtime calling convention), which |
| 7036 | // might be cluttered by the potential first read barrier |
| 7037 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7038 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7039 | break; |
| 7040 | } |
| 7041 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7042 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7043 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7044 | // We can not get false positives by doing this. |
| 7045 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7046 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7047 | temp_loc, |
| 7048 | obj_loc, |
| 7049 | class_offset, |
| 7050 | kWithoutReadBarrier); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 7051 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7052 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7053 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7054 | temp_loc, |
| 7055 | temp_loc, |
| 7056 | iftable_offset, |
| 7057 | kWithoutReadBarrier); |
| 7058 | // Iftable is never null. |
| 7059 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
| 7060 | // Maybe poison the `cls` for direct comparison with memory. |
| 7061 | __ MaybePoisonHeapReference(cls.AsRegister<CpuRegister>()); |
| 7062 | // Loop through the iftable and check if any class matches. |
| 7063 | NearLabel start_loop; |
| 7064 | __ Bind(&start_loop); |
| 7065 | // Need to subtract first to handle the empty array case. |
| 7066 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| 7067 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7068 | // Go to next interface if the classes do not match. |
| 7069 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 7070 | CodeGeneratorX86_64::ArrayAddress(temp, |
| 7071 | maybe_temp2_loc, |
| 7072 | TIMES_4, |
| 7073 | object_array_data_offset)); |
| 7074 | __ j(kNotEqual, &start_loop); // Return if same class. |
| 7075 | // If `cls` was poisoned above, unpoison it. |
| 7076 | __ MaybeUnpoisonHeapReference(cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7077 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7078 | } |
| 7079 | |
| 7080 | case TypeCheckKind::kBitstringCheck: { |
| 7081 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7082 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7083 | temp_loc, |
| 7084 | obj_loc, |
| 7085 | class_offset, |
| 7086 | kWithoutReadBarrier); |
| 7087 | |
| 7088 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 7089 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 7090 | break; |
| 7091 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7092 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7093 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7094 | if (done.IsLinked()) { |
| 7095 | __ Bind(&done); |
| 7096 | } |
| 7097 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7098 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7099 | } |
| 7100 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7101 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7102 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7103 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7104 | InvokeRuntimeCallingConvention calling_convention; |
| 7105 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7106 | } |
| 7107 | |
| 7108 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7109 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7110 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7111 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7112 | if (instruction->IsEnter()) { |
| 7113 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7114 | } else { |
| 7115 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7116 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7117 | } |
| 7118 | |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 7119 | void LocationsBuilderX86_64::VisitX86AndNot(HX86AndNot* instruction) { |
| 7120 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 7121 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 7122 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 7123 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7124 | // There is no immediate variant of negated bitwise and in X86. |
| 7125 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7126 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7127 | } |
| 7128 | |
| 7129 | void LocationsBuilderX86_64::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 7130 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 7131 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 7132 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 7133 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7134 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7135 | } |
| 7136 | |
| 7137 | void InstructionCodeGeneratorX86_64::VisitX86AndNot(HX86AndNot* instruction) { |
| 7138 | LocationSummary* locations = instruction->GetLocations(); |
| 7139 | Location first = locations->InAt(0); |
| 7140 | Location second = locations->InAt(1); |
| 7141 | Location dest = locations->Out(); |
| 7142 | __ andn(dest.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 7143 | } |
| 7144 | |
| 7145 | void InstructionCodeGeneratorX86_64::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 7146 | LocationSummary* locations = instruction->GetLocations(); |
| 7147 | Location src = locations->InAt(0); |
| 7148 | Location dest = locations->Out(); |
| 7149 | switch (instruction->GetOpKind()) { |
| 7150 | case HInstruction::kAnd: |
| 7151 | __ blsr(dest.AsRegister<CpuRegister>(), src.AsRegister<CpuRegister>()); |
| 7152 | break; |
| 7153 | case HInstruction::kXor: |
| 7154 | __ blsmsk(dest.AsRegister<CpuRegister>(), src.AsRegister<CpuRegister>()); |
| 7155 | break; |
| 7156 | default: |
| 7157 | LOG(FATAL) << "Unreachable"; |
| 7158 | } |
| 7159 | } |
| 7160 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7161 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 7162 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 7163 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 7164 | |
| 7165 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7166 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7167 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7168 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7169 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7170 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 7171 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7172 | locations->SetOut(Location::SameAsFirstInput()); |
| 7173 | } |
| 7174 | |
| 7175 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 7176 | HandleBitwiseOperation(instruction); |
| 7177 | } |
| 7178 | |
| 7179 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 7180 | HandleBitwiseOperation(instruction); |
| 7181 | } |
| 7182 | |
| 7183 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 7184 | HandleBitwiseOperation(instruction); |
| 7185 | } |
| 7186 | |
| 7187 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7188 | LocationSummary* locations = instruction->GetLocations(); |
| 7189 | Location first = locations->InAt(0); |
| 7190 | Location second = locations->InAt(1); |
| 7191 | DCHECK(first.Equals(locations->Out())); |
| 7192 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7193 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7194 | if (second.IsRegister()) { |
| 7195 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7196 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7197 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7198 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7199 | } else { |
| 7200 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7201 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7202 | } |
| 7203 | } else if (second.IsConstant()) { |
| 7204 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 7205 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7206 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7207 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7208 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7209 | } else { |
| 7210 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7211 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7212 | } |
| 7213 | } else { |
| 7214 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 7215 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7216 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7217 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7218 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7219 | } else { |
| 7220 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7221 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7222 | } |
| 7223 | } |
| 7224 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7225 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7226 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 7227 | bool second_is_constant = false; |
| 7228 | int64_t value = 0; |
| 7229 | if (second.IsConstant()) { |
| 7230 | second_is_constant = true; |
| 7231 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7232 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 7233 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7234 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7235 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7236 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 7237 | if (is_int32_value) { |
| 7238 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 7239 | } else { |
| 7240 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 7241 | } |
| 7242 | } else if (second.IsDoubleStackSlot()) { |
| 7243 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7244 | } else { |
| 7245 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 7246 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7247 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7248 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 7249 | if (is_int32_value) { |
| 7250 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 7251 | } else { |
| 7252 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 7253 | } |
| 7254 | } else if (second.IsDoubleStackSlot()) { |
| 7255 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7256 | } else { |
| 7257 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 7258 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7259 | } else { |
| 7260 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7261 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 7262 | if (is_int32_value) { |
| 7263 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 7264 | } else { |
| 7265 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 7266 | } |
| 7267 | } else if (second.IsDoubleStackSlot()) { |
| 7268 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7269 | } else { |
| 7270 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 7271 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7272 | } |
| 7273 | } |
| 7274 | } |
| 7275 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7276 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister( |
| 7277 | HInstruction* instruction, |
| 7278 | Location out, |
| 7279 | uint32_t offset, |
| 7280 | Location maybe_temp, |
| 7281 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7282 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7283 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7284 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7285 | if (kUseBakerReadBarrier) { |
| 7286 | // Load with fast path based Baker's read barrier. |
| 7287 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7288 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7289 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7290 | } else { |
| 7291 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7292 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7293 | // in the following move operation, as we will need it for the |
| 7294 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7295 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7296 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7297 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7298 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7299 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7300 | } |
| 7301 | } else { |
| 7302 | // Plain load with no read barrier. |
| 7303 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7304 | __ movl(out_reg, Address(out_reg, offset)); |
| 7305 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7306 | } |
| 7307 | } |
| 7308 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7309 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters( |
| 7310 | HInstruction* instruction, |
| 7311 | Location out, |
| 7312 | Location obj, |
| 7313 | uint32_t offset, |
| 7314 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7315 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 7316 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7317 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7318 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7319 | if (kUseBakerReadBarrier) { |
| 7320 | // Load with fast path based Baker's read barrier. |
| 7321 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7322 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7323 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7324 | } else { |
| 7325 | // Load with slow path based read barrier. |
| 7326 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7327 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7328 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7329 | } |
| 7330 | } else { |
| 7331 | // Plain load with no read barrier. |
| 7332 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7333 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7334 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7335 | } |
| 7336 | } |
| 7337 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7338 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad( |
| 7339 | HInstruction* instruction, |
| 7340 | Location root, |
| 7341 | const Address& address, |
| 7342 | Label* fixup_label, |
| 7343 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7344 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7345 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7346 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7347 | if (kUseBakerReadBarrier) { |
| 7348 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7349 | // Baker's read barrier are used: |
| 7350 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7351 | // root = obj.field; |
| 7352 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7353 | // if (temp != null) { |
| 7354 | // root = temp(root) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7355 | // } |
| 7356 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7357 | // /* GcRoot<mirror::Object> */ root = *address |
| 7358 | __ movl(root_reg, address); |
| 7359 | if (fixup_label != nullptr) { |
| 7360 | __ Bind(fixup_label); |
| 7361 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7362 | static_assert( |
| 7363 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7364 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7365 | "have different sizes."); |
| 7366 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7367 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7368 | "have different sizes."); |
| 7369 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7370 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7371 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7372 | instruction, root, /* unpoison_ref_before_marking= */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7373 | codegen_->AddSlowPath(slow_path); |
| 7374 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7375 | // Test the `Thread::Current()->pReadBarrierMarkReg ## root.reg()` entrypoint. |
| 7376 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7377 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(root.reg()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7378 | __ gs()->cmpl(Address::Absolute(entry_point_offset, /* no_rip= */ true), Immediate(0)); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7379 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7380 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7381 | __ Bind(slow_path->GetExitLabel()); |
| 7382 | } else { |
| 7383 | // GC root loaded through a slow path for read barriers other |
| 7384 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7385 | // /* GcRoot<mirror::Object>* */ root = address |
| 7386 | __ leaq(root_reg, address); |
| 7387 | if (fixup_label != nullptr) { |
| 7388 | __ Bind(fixup_label); |
| 7389 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7390 | // /* mirror::Object* */ root = root->Read() |
| 7391 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7392 | } |
| 7393 | } else { |
| 7394 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7395 | // /* GcRoot<mirror::Object> */ root = *address |
| 7396 | __ movl(root_reg, address); |
| 7397 | if (fixup_label != nullptr) { |
| 7398 | __ Bind(fixup_label); |
| 7399 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7400 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7401 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7402 | } |
| 7403 | } |
| 7404 | |
| 7405 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7406 | Location ref, |
| 7407 | CpuRegister obj, |
| 7408 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7409 | bool needs_null_check) { |
| 7410 | DCHECK(kEmitCompilerReadBarrier); |
| 7411 | DCHECK(kUseBakerReadBarrier); |
| 7412 | |
| 7413 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7414 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7415 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7416 | } |
| 7417 | |
| 7418 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7419 | Location ref, |
| 7420 | CpuRegister obj, |
| 7421 | uint32_t data_offset, |
| 7422 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7423 | bool needs_null_check) { |
| 7424 | DCHECK(kEmitCompilerReadBarrier); |
| 7425 | DCHECK(kUseBakerReadBarrier); |
| 7426 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7427 | static_assert( |
| 7428 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7429 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7430 | // /* HeapReference<Object> */ ref = |
| 7431 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7432 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7433 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7434 | } |
| 7435 | |
| 7436 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7437 | Location ref, |
| 7438 | CpuRegister obj, |
| 7439 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7440 | bool needs_null_check, |
| 7441 | bool always_update_field, |
| 7442 | CpuRegister* temp1, |
| 7443 | CpuRegister* temp2) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7444 | DCHECK(kEmitCompilerReadBarrier); |
| 7445 | DCHECK(kUseBakerReadBarrier); |
| 7446 | |
| 7447 | // In slow path based read barriers, the read barrier call is |
| 7448 | // inserted after the original load. However, in fast path based |
| 7449 | // Baker's read barriers, we need to perform the load of |
| 7450 | // mirror::Object::monitor_ *before* the original reference load. |
| 7451 | // This load-load ordering is required by the read barrier. |
| 7452 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7453 | // |
| 7454 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7455 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7456 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7457 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7458 | // if (is_gray) { |
| 7459 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7460 | // } |
| 7461 | // |
| 7462 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7463 | // slightly more complex as: |
| 7464 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7465 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7466 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 7467 | // 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] | 7468 | // - it performs additional checks that we do not do here for |
| 7469 | // performance reasons. |
| 7470 | |
| 7471 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7472 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7473 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7474 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
Roland Levillain | 14e5a29 | 2018-06-28 12:00:56 +0100 | [diff] [blame] | 7475 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7476 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7477 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7478 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7479 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7480 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7481 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7482 | // ref = ReadBarrier::Mark(ref); |
| 7483 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7484 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7485 | if (needs_null_check) { |
| 7486 | MaybeRecordImplicitNullCheck(instruction); |
| 7487 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7488 | |
| 7489 | // Load fence to prevent load-load reordering. |
| 7490 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 7491 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7492 | |
| 7493 | // The actual reference load. |
| 7494 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7495 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7496 | |
| 7497 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7498 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7499 | SlowPathCode* slow_path; |
| 7500 | if (always_update_field) { |
| 7501 | DCHECK(temp1 != nullptr); |
| 7502 | DCHECK(temp2 != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7503 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7504 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp1, *temp2); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7505 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7506 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7507 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7508 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7509 | AddSlowPath(slow_path); |
| 7510 | |
| 7511 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7512 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7513 | |
| 7514 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7515 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7516 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7517 | __ Bind(slow_path->GetExitLabel()); |
| 7518 | } |
| 7519 | |
| 7520 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7521 | Location out, |
| 7522 | Location ref, |
| 7523 | Location obj, |
| 7524 | uint32_t offset, |
| 7525 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7526 | DCHECK(kEmitCompilerReadBarrier); |
| 7527 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7528 | // Insert a slow path based read barrier *after* the reference load. |
| 7529 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7530 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7531 | // reference will be carried out by the runtime within the slow |
| 7532 | // path. |
| 7533 | // |
| 7534 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7535 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7536 | // not used by the artReadBarrierSlow entry point. |
| 7537 | // |
| 7538 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7539 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7540 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 7541 | AddSlowPath(slow_path); |
| 7542 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7543 | __ jmp(slow_path->GetEntryLabel()); |
| 7544 | __ Bind(slow_path->GetExitLabel()); |
| 7545 | } |
| 7546 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7547 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7548 | Location out, |
| 7549 | Location ref, |
| 7550 | Location obj, |
| 7551 | uint32_t offset, |
| 7552 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7553 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7554 | // Baker's read barriers shall be handled by the fast path |
| 7555 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 7556 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7557 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7558 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7559 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7560 | } else if (kPoisonHeapReferences) { |
| 7561 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 7562 | } |
| 7563 | } |
| 7564 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7565 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7566 | Location out, |
| 7567 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7568 | DCHECK(kEmitCompilerReadBarrier); |
| 7569 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7570 | // Insert a slow path based read barrier *after* the GC root load. |
| 7571 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7572 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7573 | // not need to do anything special for this here. |
| 7574 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7575 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7576 | AddSlowPath(slow_path); |
| 7577 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7578 | __ jmp(slow_path->GetEntryLabel()); |
| 7579 | __ Bind(slow_path->GetExitLabel()); |
| 7580 | } |
| 7581 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7582 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7583 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7584 | LOG(FATAL) << "Unreachable"; |
| 7585 | } |
| 7586 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7587 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7588 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7589 | LOG(FATAL) << "Unreachable"; |
| 7590 | } |
| 7591 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7592 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7593 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7594 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7595 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7596 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7597 | locations->AddTemp(Location::RequiresRegister()); |
| 7598 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7599 | } |
| 7600 | |
| 7601 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7602 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7603 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7604 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7605 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 7606 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 7607 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7608 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7609 | |
| 7610 | // Should we generate smaller inline compare/jumps? |
| 7611 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7612 | // Figure out the correct compare values and jump conditions. |
| 7613 | // Handle the first compare/branch as a special case because it might |
| 7614 | // jump to the default case. |
| 7615 | DCHECK_GT(num_entries, 2u); |
| 7616 | Condition first_condition; |
| 7617 | uint32_t index; |
| 7618 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7619 | if (lower_bound != 0) { |
| 7620 | first_condition = kLess; |
| 7621 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 7622 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7623 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 7624 | |
| 7625 | index = 1; |
| 7626 | } else { |
| 7627 | // Handle all the compare/jumps below. |
| 7628 | first_condition = kBelow; |
| 7629 | index = 0; |
| 7630 | } |
| 7631 | |
| 7632 | // Handle the rest of the compare/jumps. |
| 7633 | for (; index + 1 < num_entries; index += 2) { |
| 7634 | int32_t compare_to_value = lower_bound + index + 1; |
| 7635 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 7636 | // Jump to successors[index] if value < case_value[index]. |
| 7637 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7638 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7639 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7640 | } |
| 7641 | |
| 7642 | if (index != num_entries) { |
| 7643 | // There are an odd number of entries. Handle the last one. |
| 7644 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 7645 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7646 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 7647 | } |
| 7648 | |
| 7649 | // And the default for any other value. |
| 7650 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7651 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 7652 | } |
| 7653 | return; |
| 7654 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7655 | |
| 7656 | // Remove the bias, if needed. |
| 7657 | Register value_reg_out = value_reg_in.AsRegister(); |
| 7658 | if (lower_bound != 0) { |
| 7659 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 7660 | value_reg_out = temp_reg.AsRegister(); |
| 7661 | } |
| 7662 | CpuRegister value_reg(value_reg_out); |
| 7663 | |
| 7664 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7665 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7666 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7667 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7668 | // We are in the range of the table. |
| 7669 | // Load the address of the jump table in the constant area. |
| 7670 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7671 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7672 | // Load the (signed) offset from the jump table. |
| 7673 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 7674 | |
| 7675 | // Add the offset to the address of the table base. |
| 7676 | __ addq(temp_reg, base_reg); |
| 7677 | |
| 7678 | // And jump. |
| 7679 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7680 | } |
| 7681 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7682 | void LocationsBuilderX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7683 | ATTRIBUTE_UNUSED) { |
| 7684 | LOG(FATAL) << "Unreachable"; |
| 7685 | } |
| 7686 | |
| 7687 | void InstructionCodeGeneratorX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7688 | ATTRIBUTE_UNUSED) { |
| 7689 | LOG(FATAL) << "Unreachable"; |
| 7690 | } |
| 7691 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7692 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 7693 | if (value == 0) { |
| 7694 | __ xorl(dest, dest); |
| 7695 | } else { |
| 7696 | __ movl(dest, Immediate(value)); |
| 7697 | } |
| 7698 | } |
| 7699 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7700 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 7701 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7702 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7703 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 7704 | } else if (IsUint<32>(value)) { |
| 7705 | // 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] | 7706 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 7707 | } else { |
| 7708 | __ movq(dest, Immediate(value)); |
| 7709 | } |
| 7710 | } |
| 7711 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 7712 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 7713 | if (value == 0) { |
| 7714 | __ xorps(dest, dest); |
| 7715 | } else { |
| 7716 | __ movss(dest, LiteralInt32Address(value)); |
| 7717 | } |
| 7718 | } |
| 7719 | |
| 7720 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 7721 | if (value == 0) { |
| 7722 | __ xorpd(dest, dest); |
| 7723 | } else { |
| 7724 | __ movsd(dest, LiteralInt64Address(value)); |
| 7725 | } |
| 7726 | } |
| 7727 | |
| 7728 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 7729 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 7730 | } |
| 7731 | |
| 7732 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 7733 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 7734 | } |
| 7735 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7736 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 7737 | if (value == 0) { |
| 7738 | __ testl(dest, dest); |
| 7739 | } else { |
| 7740 | __ cmpl(dest, Immediate(value)); |
| 7741 | } |
| 7742 | } |
| 7743 | |
| 7744 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 7745 | if (IsInt<32>(value)) { |
| 7746 | if (value == 0) { |
| 7747 | __ testq(dest, dest); |
| 7748 | } else { |
| 7749 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 7750 | } |
| 7751 | } else { |
| 7752 | // Value won't fit in an int. |
| 7753 | __ cmpq(dest, LiteralInt64Address(value)); |
| 7754 | } |
| 7755 | } |
| 7756 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7757 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 7758 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7759 | GenerateIntCompare(lhs_reg, rhs); |
| 7760 | } |
| 7761 | |
| 7762 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7763 | if (rhs.IsConstant()) { |
| 7764 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7765 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7766 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7767 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7768 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7769 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7770 | } |
| 7771 | } |
| 7772 | |
| 7773 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 7774 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 7775 | if (rhs.IsConstant()) { |
| 7776 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 7777 | Compare64BitValue(lhs_reg, value); |
| 7778 | } else if (rhs.IsDoubleStackSlot()) { |
| 7779 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 7780 | } else { |
| 7781 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 7782 | } |
| 7783 | } |
| 7784 | |
| 7785 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 7786 | Location index, |
| 7787 | ScaleFactor scale, |
| 7788 | uint32_t data_offset) { |
| 7789 | return index.IsConstant() ? |
| 7790 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7791 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 7792 | } |
| 7793 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 7794 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 7795 | DCHECK(dest.IsDoubleStackSlot()); |
| 7796 | if (IsInt<32>(value)) { |
| 7797 | // Can move directly as an int32 constant. |
| 7798 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 7799 | Immediate(static_cast<int32_t>(value))); |
| 7800 | } else { |
| 7801 | Load64BitValue(CpuRegister(TMP), value); |
| 7802 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 7803 | } |
| 7804 | } |
| 7805 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7806 | /** |
| 7807 | * Class to handle late fixup of offsets into constant area. |
| 7808 | */ |
| 7809 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 7810 | public: |
| 7811 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 7812 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7813 | |
| 7814 | protected: |
| 7815 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7816 | |
| 7817 | CodeGeneratorX86_64* codegen_; |
| 7818 | |
| 7819 | private: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7820 | void Process(const MemoryRegion& region, int pos) override { |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7821 | // Patch the correct offset for the instruction. We use the address of the |
| 7822 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 7823 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7824 | int32_t relative_position = constant_offset - pos; |
| 7825 | |
| 7826 | // Patch in the right value. |
| 7827 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7828 | } |
| 7829 | |
| 7830 | // Location in constant area that the fixup refers to. |
| 7831 | size_t offset_into_constant_area_; |
| 7832 | }; |
| 7833 | |
| 7834 | /** |
| 7835 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7836 | * constant area. |
| 7837 | */ |
| 7838 | class JumpTableRIPFixup : public RIPFixup { |
| 7839 | public: |
| 7840 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 7841 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7842 | |
| 7843 | void CreateJumpTable() { |
| 7844 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7845 | |
| 7846 | // Ensure that the reference to the jump table has the correct offset. |
| 7847 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7848 | SetOffset(offset_in_constant_table); |
| 7849 | |
| 7850 | // Compute the offset from the start of the function to this jump table. |
| 7851 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7852 | |
| 7853 | // Populate the jump table with the correct values for the jump table. |
| 7854 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7855 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7856 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7857 | // The value that we want is the target offset - the position of the table. |
| 7858 | for (int32_t i = 0; i < num_entries; i++) { |
| 7859 | HBasicBlock* b = successors[i]; |
| 7860 | Label* l = codegen_->GetLabelOf(b); |
| 7861 | DCHECK(l->IsBound()); |
| 7862 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7863 | assembler->AppendInt32(offset_to_block); |
| 7864 | } |
| 7865 | } |
| 7866 | |
| 7867 | private: |
| 7868 | const HPackedSwitch* switch_instr_; |
| 7869 | }; |
| 7870 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7871 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7872 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7873 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7874 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7875 | // 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] | 7876 | assembler->Align(4, 0); |
| 7877 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7878 | |
| 7879 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7880 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7881 | jump_table->CreateJumpTable(); |
| 7882 | } |
| 7883 | |
| 7884 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7885 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7886 | } |
| 7887 | |
| 7888 | // And finish up. |
| 7889 | CodeGenerator::Finalize(allocator); |
| 7890 | } |
| 7891 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7892 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7893 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddDouble(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7894 | return Address::RIP(fixup); |
| 7895 | } |
| 7896 | |
| 7897 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7898 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddFloat(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7899 | return Address::RIP(fixup); |
| 7900 | } |
| 7901 | |
| 7902 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7903 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt32(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7904 | return Address::RIP(fixup); |
| 7905 | } |
| 7906 | |
| 7907 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7908 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt64(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7909 | return Address::RIP(fixup); |
| 7910 | } |
| 7911 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7912 | // TODO: trg as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7913 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7914 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7915 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7916 | return; |
| 7917 | } |
| 7918 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7919 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7920 | |
| 7921 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7922 | if (trg.Equals(return_loc)) { |
| 7923 | return; |
| 7924 | } |
| 7925 | |
| 7926 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7927 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7928 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7929 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7930 | } |
| 7931 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7932 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7933 | // Create a fixup to be used to create and address the jump table. |
| 7934 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7935 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7936 | |
| 7937 | // We have to populate the jump tables. |
| 7938 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7939 | return Address::RIP(table_fixup); |
| 7940 | } |
| 7941 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7942 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7943 | const Address& addr_high, |
| 7944 | int64_t v, |
| 7945 | HInstruction* instruction) { |
| 7946 | if (IsInt<32>(v)) { |
| 7947 | int32_t v_32 = v; |
| 7948 | __ movq(addr_low, Immediate(v_32)); |
| 7949 | MaybeRecordImplicitNullCheck(instruction); |
| 7950 | } else { |
| 7951 | // Didn't fit in a register. Do it in pieces. |
| 7952 | int32_t low_v = Low32Bits(v); |
| 7953 | int32_t high_v = High32Bits(v); |
| 7954 | __ movl(addr_low, Immediate(low_v)); |
| 7955 | MaybeRecordImplicitNullCheck(instruction); |
| 7956 | __ movl(addr_high, Immediate(high_v)); |
| 7957 | } |
| 7958 | } |
| 7959 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7960 | void CodeGeneratorX86_64::PatchJitRootUse(uint8_t* code, |
| 7961 | const uint8_t* roots_data, |
| 7962 | const PatchInfo<Label>& info, |
| 7963 | uint64_t index_in_table) const { |
| 7964 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7965 | uintptr_t address = |
| 7966 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 7967 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7968 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7969 | dchecked_integral_cast<uint32_t>(address); |
| 7970 | } |
| 7971 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7972 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7973 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7974 | 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] | 7975 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7976 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7977 | } |
| 7978 | |
| 7979 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7980 | 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] | 7981 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7982 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7983 | } |
| 7984 | } |
| 7985 | |
Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 7986 | bool LocationsBuilderX86_64::CpuHasAvxFeatureFlag() { |
| 7987 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 7988 | } |
| 7989 | |
| 7990 | bool LocationsBuilderX86_64::CpuHasAvx2FeatureFlag() { |
| 7991 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 7992 | } |
| 7993 | |
| 7994 | bool InstructionCodeGeneratorX86_64::CpuHasAvxFeatureFlag() { |
| 7995 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 7996 | } |
| 7997 | |
| 7998 | bool InstructionCodeGeneratorX86_64::CpuHasAvx2FeatureFlag() { |
| 7999 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 8000 | } |
| 8001 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8002 | #undef __ |
| 8003 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 8004 | } // namespace x86_64 |
| 8005 | } // namespace art |