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" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 37 | #include "scoped_thread_state_change-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 38 | #include "thread.h" |
| 39 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 40 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 41 | #include "utils/x86_64/assembler_x86_64.h" |
| 42 | #include "utils/x86_64/managed_register_x86_64.h" |
| 43 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 44 | namespace art { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 45 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 46 | template<class MirrorType> |
| 47 | class GcRoot; |
| 48 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 49 | namespace x86_64 { |
| 50 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 51 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 52 | static constexpr Register kMethodRegisterArgument = RDI; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 53 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 54 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 55 | // generates less code/data with a small num_entries. |
| 56 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 57 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 58 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 59 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 60 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 61 | static constexpr int kC2ConditionMask = 0x400; |
| 62 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 63 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 64 | // Custom calling convention: RAX serves as both input and output. |
| 65 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 66 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 67 | return caller_saves; |
| 68 | } |
| 69 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 70 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 71 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 72 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 74 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 76 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 78 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 79 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 81 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 82 | // Live registers will be restored in the catch block if caught. |
| 83 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 84 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 85 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 86 | instruction_, |
| 87 | instruction_->GetDexPc(), |
| 88 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 89 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 90 | } |
| 91 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 92 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 93 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 94 | const char* GetDescription() const override { return "NullCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 95 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 96 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 97 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 98 | }; |
| 99 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 100 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 102 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 104 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 105 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 107 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 108 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 111 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 112 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 113 | const char* GetDescription() const override { return "DivZeroCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 114 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 116 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 117 | }; |
| 118 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 119 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 121 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, DataType::Type type, bool is_div) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 122 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 123 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 124 | void EmitNativeCode(CodeGenerator* codegen) override { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 125 | __ Bind(GetEntryLabel()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 126 | if (type_ == DataType::Type::kInt32) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 127 | if (is_div_) { |
| 128 | __ negl(cpu_reg_); |
| 129 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 130 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 133 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 134 | DCHECK_EQ(DataType::Type::kInt64, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 135 | if (is_div_) { |
| 136 | __ negq(cpu_reg_); |
| 137 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 138 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 139 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 140 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 141 | __ jmp(GetExitLabel()); |
| 142 | } |
| 143 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 144 | const char* GetDescription() const override { return "DivRemMinusOneSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 145 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 146 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 147 | const CpuRegister cpu_reg_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 148 | const DataType::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 149 | const bool is_div_; |
| 150 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 153 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 154 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 155 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 156 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 157 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 158 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 159 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 160 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 161 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 162 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 163 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 164 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 165 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 166 | if (successor_ == nullptr) { |
| 167 | __ jmp(GetReturnLabel()); |
| 168 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 169 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 170 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 173 | Label* GetReturnLabel() { |
| 174 | DCHECK(successor_ == nullptr); |
| 175 | return &return_label_; |
| 176 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 177 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 178 | HBasicBlock* GetSuccessor() const { |
| 179 | return successor_; |
| 180 | } |
| 181 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 182 | const char* GetDescription() const override { return "SuspendCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 183 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 184 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 185 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 186 | Label return_label_; |
| 187 | |
| 188 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 189 | }; |
| 190 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 191 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 192 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 193 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 194 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 195 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 196 | void EmitNativeCode(CodeGenerator* codegen) override { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 197 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 198 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 199 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 200 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 201 | // Live registers will be restored in the catch block if caught. |
| 202 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 203 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 204 | // Are we using an array length from memory? |
| 205 | HInstruction* array_length = instruction_->InputAt(1); |
| 206 | Location length_loc = locations->InAt(1); |
| 207 | InvokeRuntimeCallingConvention calling_convention; |
| 208 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 209 | // Load the array length into our temporary. |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 210 | HArrayLength* length = array_length->AsArrayLength(); |
Nicolas Geoffray | 003444a | 2017-10-17 10:58:42 +0100 | [diff] [blame] | 211 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 212 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 213 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 214 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 215 | // Check for conflicts with index. |
| 216 | if (length_loc.Equals(locations->InAt(0))) { |
| 217 | // We know we aren't using parameter 2. |
| 218 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 219 | } |
| 220 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 221 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 222 | __ shrl(length_loc.AsRegister<CpuRegister>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 223 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 224 | } |
| 225 | |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 226 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 227 | // move resolver. |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 228 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 229 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 230 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 231 | DataType::Type::kInt32, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 232 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 233 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 234 | DataType::Type::kInt32); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 235 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 236 | ? kQuickThrowStringBounds |
| 237 | : kQuickThrowArrayBounds; |
| 238 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 239 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 240 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 241 | } |
| 242 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 243 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 244 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 245 | const char* GetDescription() const override { return "BoundsCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 246 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 247 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 248 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 249 | }; |
| 250 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 251 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 252 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 253 | LoadClassSlowPathX86_64(HLoadClass* cls, HInstruction* at) |
| 254 | : SlowPathCode(at), cls_(cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 255 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 256 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 257 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 258 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 259 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 260 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 261 | Location out = locations->Out(); |
| 262 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 263 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 264 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 265 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 266 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 267 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 268 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 270 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 271 | if (must_resolve_type) { |
| 272 | DCHECK(IsSameDexFile(cls_->GetDexFile(), x86_64_codegen->GetGraph()->GetDexFile())); |
| 273 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 274 | __ movl(CpuRegister(RAX), Immediate(type_index.index_)); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 275 | if (cls_->NeedsAccessCheck()) { |
| 276 | CheckEntrypointTypes<kQuickResolveTypeAndVerifyAccess, void*, uint32_t>(); |
| 277 | x86_64_codegen->InvokeRuntime(kQuickResolveTypeAndVerifyAccess, instruction_, dex_pc, this); |
| 278 | } else { |
| 279 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| 280 | x86_64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 281 | } |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 282 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 283 | } else { |
| 284 | DCHECK(must_do_clinit); |
| 285 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 286 | x86_64_codegen->Move(Location::RegisterLocation(RAX), source); |
| 287 | } |
| 288 | if (must_do_clinit) { |
| 289 | x86_64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 290 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 291 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 292 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 293 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 294 | if (out.IsValid()) { |
| 295 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 296 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 299 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 300 | __ jmp(GetExitLabel()); |
| 301 | } |
| 302 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 303 | const char* GetDescription() const override { return "LoadClassSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 304 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 305 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 306 | // The class this slow path will load. |
| 307 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 308 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 309 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 310 | }; |
| 311 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 312 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
| 313 | public: |
| 314 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
| 315 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 316 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 317 | LocationSummary* locations = instruction_->GetLocations(); |
| 318 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 319 | |
| 320 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 321 | __ Bind(GetEntryLabel()); |
| 322 | SaveLiveRegisters(codegen, locations); |
| 323 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 324 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 325 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 326 | __ movl(CpuRegister(RAX), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 327 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
| 328 | instruction_, |
| 329 | instruction_->GetDexPc(), |
| 330 | this); |
| 331 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 332 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 333 | RestoreLiveRegisters(codegen, locations); |
| 334 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 335 | __ jmp(GetExitLabel()); |
| 336 | } |
| 337 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 338 | const char* GetDescription() const override { return "LoadStringSlowPathX86_64"; } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 339 | |
| 340 | private: |
| 341 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 342 | }; |
| 343 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 344 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 345 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 346 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 347 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 348 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 349 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 350 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 351 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 352 | DCHECK(instruction_->IsCheckCast() |
| 353 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 354 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 355 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 356 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 357 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 358 | if (kPoisonHeapReferences && |
| 359 | instruction_->IsCheckCast() && |
| 360 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 361 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 362 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<CpuRegister>()); |
| 363 | } |
| 364 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 365 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 366 | SaveLiveRegisters(codegen, locations); |
| 367 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 368 | |
| 369 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 370 | // move resolver. |
| 371 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 372 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 373 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 374 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 375 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 376 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 377 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 378 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 379 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 380 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 381 | } else { |
| 382 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 383 | x86_64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 384 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 385 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 386 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 387 | if (!is_fatal_) { |
| 388 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 389 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 390 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 391 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 392 | RestoreLiveRegisters(codegen, locations); |
| 393 | __ jmp(GetExitLabel()); |
| 394 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 397 | const char* GetDescription() const override { return "TypeCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 398 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 399 | bool IsFatal() const override { return is_fatal_; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 400 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 401 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 402 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 403 | |
| 404 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 405 | }; |
| 406 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 407 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 408 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 409 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 410 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 411 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 412 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 413 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 414 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 415 | LocationSummary* locations = instruction_->GetLocations(); |
| 416 | SaveLiveRegisters(codegen, locations); |
| 417 | InvokeRuntimeCallingConvention calling_convention; |
| 418 | x86_64_codegen->Load32BitValue( |
| 419 | CpuRegister(calling_convention.GetRegisterAt(0)), |
| 420 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 421 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 422 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 425 | const char* GetDescription() const override { return "DeoptimizationSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 426 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 427 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 428 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 429 | }; |
| 430 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 431 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 432 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 433 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 434 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 435 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 436 | LocationSummary* locations = instruction_->GetLocations(); |
| 437 | __ Bind(GetEntryLabel()); |
| 438 | SaveLiveRegisters(codegen, locations); |
| 439 | |
| 440 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 441 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 442 | parallel_move.AddMove( |
| 443 | locations->InAt(0), |
| 444 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 445 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 446 | nullptr); |
| 447 | parallel_move.AddMove( |
| 448 | locations->InAt(1), |
| 449 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 450 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 451 | nullptr); |
| 452 | parallel_move.AddMove( |
| 453 | locations->InAt(2), |
| 454 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 455 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 456 | nullptr); |
| 457 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 458 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 459 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 460 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 461 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 462 | RestoreLiveRegisters(codegen, locations); |
| 463 | __ jmp(GetExitLabel()); |
| 464 | } |
| 465 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 466 | const char* GetDescription() const override { return "ArraySetSlowPathX86_64"; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 467 | |
| 468 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 469 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 470 | }; |
| 471 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 472 | // Slow path marking an object reference `ref` during a read |
| 473 | // barrier. The field `obj.field` in the object `obj` holding this |
| 474 | // reference does not get updated by this slow path after marking (see |
| 475 | // ReadBarrierMarkAndUpdateFieldSlowPathX86_64 below for that). |
| 476 | // |
| 477 | // This means that after the execution of this slow path, `ref` will |
| 478 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 479 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 480 | // probably still be a from-space reference (unless it gets updated by |
| 481 | // another thread, or if another thread installed another object |
| 482 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 483 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 484 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 485 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, |
| 486 | Location ref, |
| 487 | bool unpoison_ref_before_marking) |
| 488 | : SlowPathCode(instruction), |
| 489 | ref_(ref), |
| 490 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 491 | DCHECK(kEmitCompilerReadBarrier); |
| 492 | } |
| 493 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 494 | const char* GetDescription() const override { return "ReadBarrierMarkSlowPathX86_64"; } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 495 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 496 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 497 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 498 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 499 | Register ref_reg = ref_cpu_reg.AsRegister(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 500 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 501 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 502 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 503 | instruction_->IsStaticFieldGet() || |
| 504 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 505 | instruction_->IsArraySet() || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 506 | instruction_->IsLoadClass() || |
| 507 | instruction_->IsLoadString() || |
| 508 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 509 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 510 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 511 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 512 | << "Unexpected instruction in read barrier marking slow path: " |
| 513 | << instruction_->DebugName(); |
| 514 | |
| 515 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 516 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 517 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 518 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 519 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 520 | // No need to save live registers; it's taken care of by the |
| 521 | // entrypoint. Also, there is no need to update the stack mask, |
| 522 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 523 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 524 | DCHECK_NE(ref_reg, RSP); |
| 525 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 526 | // "Compact" slow path, saving two moves. |
| 527 | // |
| 528 | // Instead of using the standard runtime calling convention (input |
| 529 | // and output in R0): |
| 530 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 531 | // RDI <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 532 | // RAX <- ReadBarrierMark(RDI) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 533 | // ref <- RAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 534 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 535 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 536 | // of a dedicated entrypoint: |
| 537 | // |
| 538 | // rX <- ReadBarrierMarkRegX(rX) |
| 539 | // |
| 540 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 541 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 542 | // This runtime call does not require a stack map. |
| 543 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 544 | __ jmp(GetExitLabel()); |
| 545 | } |
| 546 | |
| 547 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 548 | // The location (register) of the marked object reference. |
| 549 | const Location ref_; |
| 550 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 551 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 552 | |
| 553 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 554 | }; |
| 555 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 556 | // Slow path marking an object reference `ref` during a read barrier, |
| 557 | // and if needed, atomically updating the field `obj.field` in the |
| 558 | // object `obj` holding this reference after marking (contrary to |
| 559 | // ReadBarrierMarkSlowPathX86_64 above, which never tries to update |
| 560 | // `obj.field`). |
| 561 | // |
| 562 | // This means that after the execution of this slow path, both `ref` |
| 563 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 564 | // hold the same to-space reference (unless another thread installed |
| 565 | // another object reference (different from `ref`) in `obj.field`). |
| 566 | class ReadBarrierMarkAndUpdateFieldSlowPathX86_64 : public SlowPathCode { |
| 567 | public: |
| 568 | ReadBarrierMarkAndUpdateFieldSlowPathX86_64(HInstruction* instruction, |
| 569 | Location ref, |
| 570 | CpuRegister obj, |
| 571 | const Address& field_addr, |
| 572 | bool unpoison_ref_before_marking, |
| 573 | CpuRegister temp1, |
| 574 | CpuRegister temp2) |
| 575 | : SlowPathCode(instruction), |
| 576 | ref_(ref), |
| 577 | obj_(obj), |
| 578 | field_addr_(field_addr), |
| 579 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 580 | temp1_(temp1), |
| 581 | temp2_(temp2) { |
| 582 | DCHECK(kEmitCompilerReadBarrier); |
| 583 | } |
| 584 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 585 | const char* GetDescription() const override { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 586 | return "ReadBarrierMarkAndUpdateFieldSlowPathX86_64"; |
| 587 | } |
| 588 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 589 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 590 | LocationSummary* locations = instruction_->GetLocations(); |
| 591 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 592 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| 593 | DCHECK(locations->CanCall()); |
| 594 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 595 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 596 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 597 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 598 | << instruction_->DebugName(); |
| 599 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 600 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 601 | |
| 602 | __ Bind(GetEntryLabel()); |
| 603 | if (unpoison_ref_before_marking_) { |
| 604 | // Object* ref = ref_addr->AsMirrorPtr() |
| 605 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| 606 | } |
| 607 | |
| 608 | // Save the old (unpoisoned) reference. |
| 609 | __ movl(temp1_, ref_cpu_reg); |
| 610 | |
| 611 | // No need to save live registers; it's taken care of by the |
| 612 | // entrypoint. Also, there is no need to update the stack mask, |
| 613 | // as this runtime call will not trigger a garbage collection. |
| 614 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 615 | DCHECK_NE(ref_reg, RSP); |
| 616 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 617 | // "Compact" slow path, saving two moves. |
| 618 | // |
| 619 | // Instead of using the standard runtime calling convention (input |
| 620 | // and output in R0): |
| 621 | // |
| 622 | // RDI <- ref |
| 623 | // RAX <- ReadBarrierMark(RDI) |
| 624 | // ref <- RAX |
| 625 | // |
| 626 | // we just use rX (the register containing `ref`) as input and output |
| 627 | // of a dedicated entrypoint: |
| 628 | // |
| 629 | // rX <- ReadBarrierMarkRegX(rX) |
| 630 | // |
| 631 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 632 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 633 | // This runtime call does not require a stack map. |
| 634 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 635 | |
| 636 | // If the new reference is different from the old reference, |
| 637 | // update the field in the holder (`*field_addr`). |
| 638 | // |
| 639 | // Note that this field could also hold a different object, if |
| 640 | // another thread had concurrently changed it. In that case, the |
| 641 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 642 | // operation below would abort the CAS, leaving the field as-is. |
| 643 | NearLabel done; |
| 644 | __ cmpl(temp1_, ref_cpu_reg); |
| 645 | __ j(kEqual, &done); |
| 646 | |
| 647 | // Update the the holder's field atomically. This may fail if |
| 648 | // mutator updates before us, but it's OK. This is achived |
| 649 | // using a strong compare-and-set (CAS) operation with relaxed |
| 650 | // memory synchronization ordering, where the expected value is |
| 651 | // the old reference and the desired value is the new reference. |
| 652 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 653 | // instruction, which requires the expected value (the old |
| 654 | // reference) to be in EAX. Save RAX beforehand, and move the |
| 655 | // expected value (stored in `temp1_`) into EAX. |
| 656 | __ movq(temp2_, CpuRegister(RAX)); |
| 657 | __ movl(CpuRegister(RAX), temp1_); |
| 658 | |
| 659 | // Convenience aliases. |
| 660 | CpuRegister base = obj_; |
| 661 | CpuRegister expected = CpuRegister(RAX); |
| 662 | CpuRegister value = ref_cpu_reg; |
| 663 | |
| 664 | bool base_equals_value = (base.AsRegister() == value.AsRegister()); |
| 665 | Register value_reg = ref_reg; |
| 666 | if (kPoisonHeapReferences) { |
| 667 | if (base_equals_value) { |
| 668 | // If `base` and `value` are the same register location, move |
| 669 | // `value_reg` to a temporary register. This way, poisoning |
| 670 | // `value_reg` won't invalidate `base`. |
| 671 | value_reg = temp1_.AsRegister(); |
| 672 | __ movl(CpuRegister(value_reg), base); |
| 673 | } |
| 674 | |
| 675 | // Check that the register allocator did not assign the location |
| 676 | // of `expected` (RAX) to `value` nor to `base`, so that heap |
| 677 | // poisoning (when enabled) works as intended below. |
| 678 | // - If `value` were equal to `expected`, both references would |
| 679 | // be poisoned twice, meaning they would not be poisoned at |
| 680 | // all, as heap poisoning uses address negation. |
| 681 | // - If `base` were equal to `expected`, poisoning `expected` |
| 682 | // would invalidate `base`. |
| 683 | DCHECK_NE(value_reg, expected.AsRegister()); |
| 684 | DCHECK_NE(base.AsRegister(), expected.AsRegister()); |
| 685 | |
| 686 | __ PoisonHeapReference(expected); |
| 687 | __ PoisonHeapReference(CpuRegister(value_reg)); |
| 688 | } |
| 689 | |
| 690 | __ LockCmpxchgl(field_addr_, CpuRegister(value_reg)); |
| 691 | |
| 692 | // If heap poisoning is enabled, we need to unpoison the values |
| 693 | // that were poisoned earlier. |
| 694 | if (kPoisonHeapReferences) { |
| 695 | if (base_equals_value) { |
| 696 | // `value_reg` has been moved to a temporary register, no need |
| 697 | // to unpoison it. |
| 698 | } else { |
| 699 | __ UnpoisonHeapReference(CpuRegister(value_reg)); |
| 700 | } |
| 701 | // No need to unpoison `expected` (RAX), as it is be overwritten below. |
| 702 | } |
| 703 | |
| 704 | // Restore RAX. |
| 705 | __ movq(CpuRegister(RAX), temp2_); |
| 706 | |
| 707 | __ Bind(&done); |
| 708 | __ jmp(GetExitLabel()); |
| 709 | } |
| 710 | |
| 711 | private: |
| 712 | // The location (register) of the marked object reference. |
| 713 | const Location ref_; |
| 714 | // The register containing the object holding the marked object reference field. |
| 715 | const CpuRegister obj_; |
| 716 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 717 | const Address field_addr_; |
| 718 | |
| 719 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 720 | const bool unpoison_ref_before_marking_; |
| 721 | |
| 722 | const CpuRegister temp1_; |
| 723 | const CpuRegister temp2_; |
| 724 | |
| 725 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86_64); |
| 726 | }; |
| 727 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 728 | // Slow path generating a read barrier for a heap reference. |
| 729 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 730 | public: |
| 731 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 732 | Location out, |
| 733 | Location ref, |
| 734 | Location obj, |
| 735 | uint32_t offset, |
| 736 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 737 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 738 | out_(out), |
| 739 | ref_(ref), |
| 740 | obj_(obj), |
| 741 | offset_(offset), |
| 742 | index_(index) { |
| 743 | DCHECK(kEmitCompilerReadBarrier); |
| 744 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 745 | // object has been overwritten by (or after) the heap object |
| 746 | // reference load to be instrumented, e.g.: |
| 747 | // |
| 748 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 749 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 750 | // |
| 751 | // In that case, we have lost the information about the original |
| 752 | // object, and the emitted read barrier cannot work properly. |
| 753 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 754 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 755 | } |
| 756 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 757 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 758 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 759 | LocationSummary* locations = instruction_->GetLocations(); |
| 760 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 761 | DCHECK(locations->CanCall()); |
| 762 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 763 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 764 | instruction_->IsStaticFieldGet() || |
| 765 | instruction_->IsArrayGet() || |
| 766 | instruction_->IsInstanceOf() || |
| 767 | instruction_->IsCheckCast() || |
Vladimir Marko | 94d2c81 | 2020-11-05 10:04:45 +0000 | [diff] [blame] | 768 | (instruction_->IsInvoke() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 769 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 770 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 771 | |
| 772 | __ Bind(GetEntryLabel()); |
| 773 | SaveLiveRegisters(codegen, locations); |
| 774 | |
| 775 | // We may have to change the index's value, but as `index_` is a |
| 776 | // constant member (like other "inputs" of this slow path), |
| 777 | // introduce a copy of it, `index`. |
| 778 | Location index = index_; |
| 779 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 780 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 781 | if (instruction_->IsArrayGet()) { |
| 782 | // Compute real offset and store it in index_. |
| 783 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 784 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 785 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 786 | // We are about to change the value of `index_reg` (see the |
| 787 | // calls to art::x86_64::X86_64Assembler::shll and |
| 788 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 789 | // has not been saved by the previous call to |
| 790 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 791 | // callee-save register -- |
| 792 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 793 | // callee-save registers, as it has been designed with the |
| 794 | // assumption that callee-save registers are supposed to be |
| 795 | // handled by the called function. So, as a callee-save |
| 796 | // register, `index_reg` _would_ eventually be saved onto |
| 797 | // the stack, but it would be too late: we would have |
| 798 | // changed its value earlier. Therefore, we manually save |
| 799 | // it here into another freely available register, |
| 800 | // `free_reg`, chosen of course among the caller-save |
| 801 | // registers (as a callee-save `free_reg` register would |
| 802 | // exhibit the same problem). |
| 803 | // |
| 804 | // Note we could have requested a temporary register from |
| 805 | // the register allocator instead; but we prefer not to, as |
| 806 | // this is a slow path, and we know we can find a |
| 807 | // caller-save register that is available. |
| 808 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 809 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 810 | index_reg = free_reg; |
| 811 | index = Location::RegisterLocation(index_reg); |
| 812 | } else { |
| 813 | // The initial register stored in `index_` has already been |
| 814 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 815 | // (as it is not a callee-save register), so we can freely |
| 816 | // use it. |
| 817 | } |
| 818 | // Shifting the index value contained in `index_reg` by the |
| 819 | // scale factor (2) cannot overflow in practice, as the |
| 820 | // runtime is unable to allocate object arrays with a size |
| 821 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 822 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 823 | static_assert( |
| 824 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 825 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 826 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 827 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 828 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 829 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 830 | // (as in the case of ArrayGet), as it is actually an offset |
| 831 | // to an object field within an object. |
| 832 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 833 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 834 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 835 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 836 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 837 | DCHECK_EQ(offset_, 0U); |
| 838 | DCHECK(index_.IsRegister()); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | // We're moving two or three locations to locations that could |
| 843 | // overlap, so we need a parallel move resolver. |
| 844 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 845 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 846 | parallel_move.AddMove(ref_, |
| 847 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 848 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 849 | nullptr); |
| 850 | parallel_move.AddMove(obj_, |
| 851 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 852 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 853 | nullptr); |
| 854 | if (index.IsValid()) { |
| 855 | parallel_move.AddMove(index, |
| 856 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 857 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 858 | nullptr); |
| 859 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 860 | } else { |
| 861 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 862 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 863 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 864 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 865 | instruction_, |
| 866 | instruction_->GetDexPc(), |
| 867 | this); |
| 868 | CheckEntrypointTypes< |
| 869 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 870 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 871 | |
| 872 | RestoreLiveRegisters(codegen, locations); |
| 873 | __ jmp(GetExitLabel()); |
| 874 | } |
| 875 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 876 | const char* GetDescription() const override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 877 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 878 | } |
| 879 | |
| 880 | private: |
| 881 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 882 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 883 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 884 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 885 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 886 | return static_cast<CpuRegister>(i); |
| 887 | } |
| 888 | } |
| 889 | // We shall never fail to find a free caller-save register, as |
| 890 | // there are more than two core caller-save registers on x86-64 |
| 891 | // (meaning it is possible to find one which is different from |
| 892 | // `ref` and `obj`). |
| 893 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 894 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 895 | UNREACHABLE(); |
| 896 | } |
| 897 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 898 | const Location out_; |
| 899 | const Location ref_; |
| 900 | const Location obj_; |
| 901 | const uint32_t offset_; |
| 902 | // An additional location containing an index to an array. |
| 903 | // Only used for HArrayGet and the UnsafeGetObject & |
| 904 | // UnsafeGetObjectVolatile intrinsics. |
| 905 | const Location index_; |
| 906 | |
| 907 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 908 | }; |
| 909 | |
| 910 | // Slow path generating a read barrier for a GC root. |
| 911 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 912 | public: |
| 913 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 914 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 915 | DCHECK(kEmitCompilerReadBarrier); |
| 916 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 917 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 918 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 919 | LocationSummary* locations = instruction_->GetLocations(); |
| 920 | DCHECK(locations->CanCall()); |
| 921 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 922 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 923 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 924 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 925 | |
| 926 | __ Bind(GetEntryLabel()); |
| 927 | SaveLiveRegisters(codegen, locations); |
| 928 | |
| 929 | InvokeRuntimeCallingConvention calling_convention; |
| 930 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 931 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 932 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 933 | instruction_, |
| 934 | instruction_->GetDexPc(), |
| 935 | this); |
| 936 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 937 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 938 | |
| 939 | RestoreLiveRegisters(codegen, locations); |
| 940 | __ jmp(GetExitLabel()); |
| 941 | } |
| 942 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 943 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathX86_64"; } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 944 | |
| 945 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 946 | const Location out_; |
| 947 | const Location root_; |
| 948 | |
| 949 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 950 | }; |
| 951 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 952 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 953 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 954 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 955 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 956 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 957 | switch (cond) { |
| 958 | case kCondEQ: return kEqual; |
| 959 | case kCondNE: return kNotEqual; |
| 960 | case kCondLT: return kLess; |
| 961 | case kCondLE: return kLessEqual; |
| 962 | case kCondGT: return kGreater; |
| 963 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 964 | case kCondB: return kBelow; |
| 965 | case kCondBE: return kBelowEqual; |
| 966 | case kCondA: return kAbove; |
| 967 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 968 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 969 | LOG(FATAL) << "Unreachable"; |
| 970 | UNREACHABLE(); |
| 971 | } |
| 972 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 973 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 974 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 975 | switch (cond) { |
| 976 | case kCondEQ: return kEqual; |
| 977 | case kCondNE: return kNotEqual; |
| 978 | case kCondLT: return kBelow; |
| 979 | case kCondLE: return kBelowEqual; |
| 980 | case kCondGT: return kAbove; |
| 981 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 982 | default: break; // should not happen |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 983 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 984 | LOG(FATAL) << "Unreachable"; |
| 985 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 986 | } |
| 987 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 988 | void CodeGeneratorX86_64::BlockNonVolatileXmmRegisters(LocationSummary* locations) { |
| 989 | // We have to ensure that the native code we call directly (such as @CriticalNative |
| 990 | // or some intrinsic helpers, say Math.sin()) doesn't clobber the XMM registers |
| 991 | // which are non-volatile for ART, but volatile for Native calls. This will ensure |
| 992 | // that they are saved in the prologue and properly restored. |
| 993 | for (FloatRegister fp_reg : non_volatile_xmm_regs) { |
| 994 | locations->AddTemp(Location::FpuRegisterLocation(fp_reg)); |
| 995 | } |
| 996 | } |
| 997 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 998 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 999 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 1000 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 1001 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 1004 | void CodeGeneratorX86_64::LoadMethod(MethodLoadKind load_kind, Location temp, HInvoke* invoke) { |
| 1005 | switch (load_kind) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1006 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 1007 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1008 | __ leal(temp.AsRegister<CpuRegister>(), |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 1009 | Address::Absolute(kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1010 | RecordBootImageMethodPatch(invoke); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1011 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1012 | case MethodLoadKind::kBootImageRelRo: { |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1013 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 1014 | __ movl(temp.AsRegister<CpuRegister>(), |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 1015 | Address::Absolute(kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1016 | RecordBootImageRelRoPatch(GetBootImageOffset(invoke)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1017 | break; |
| 1018 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1019 | case MethodLoadKind::kBssEntry: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1020 | __ movq(temp.AsRegister<CpuRegister>(), |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 1021 | Address::Absolute(kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1022 | RecordMethodBssEntryPatch(invoke); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 1023 | // No need for memory fence, thanks to the x86-64 memory model. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1024 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1025 | } |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 1026 | case MethodLoadKind::kJitDirectAddress: { |
| 1027 | Load64BitValue(temp.AsRegister<CpuRegister>(), |
| 1028 | reinterpret_cast<int64_t>(invoke->GetResolvedMethod())); |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 1029 | break; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 1030 | } |
| 1031 | case MethodLoadKind::kRuntimeCall: { |
| 1032 | // Test situation, don't do anything. |
| 1033 | break; |
| 1034 | } |
| 1035 | default: { |
| 1036 | LOG(FATAL) << "Load kind should have already been handled " << load_kind; |
| 1037 | UNREACHABLE(); |
| 1038 | } |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall( |
| 1043 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| 1044 | // All registers are assumed to be correctly set up. |
| 1045 | |
| 1046 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 1047 | switch (invoke->GetMethodLoadKind()) { |
| 1048 | case MethodLoadKind::kStringInit: { |
| 1049 | // temp = thread->string_init_entrypoint |
| 1050 | uint32_t offset = |
| 1051 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 1052 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip= */ true)); |
| 1053 | break; |
| 1054 | } |
| 1055 | case MethodLoadKind::kRecursive: { |
| 1056 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodIndex()); |
| 1057 | break; |
| 1058 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1059 | case MethodLoadKind::kRuntimeCall: { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1060 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 1061 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1062 | } |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1063 | case MethodLoadKind::kBootImageLinkTimePcRelative: |
| 1064 | // For kCallCriticalNative we skip loading the method and do the call directly. |
| 1065 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
| 1066 | break; |
| 1067 | } |
| 1068 | FALLTHROUGH_INTENDED; |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 1069 | default: { |
| 1070 | LoadMethod(invoke->GetMethodLoadKind(), temp, invoke); |
| 1071 | break; |
| 1072 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | switch (invoke->GetCodePtrLocation()) { |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1076 | case CodePtrLocation::kCallSelf: |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1077 | __ call(&frame_entry_label_); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1078 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1079 | break; |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1080 | case CodePtrLocation::kCallCriticalNative: { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1081 | size_t out_frame_size = |
| 1082 | PrepareCriticalNativeCall<CriticalNativeCallingConventionVisitorX86_64, |
| 1083 | kNativeStackAlignment, |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1084 | GetCriticalNativeDirectCallFrameSize>(invoke); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1085 | if (invoke->GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative) { |
| 1086 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| 1087 | __ call(Address::Absolute(kPlaceholder32BitOffset, /* no_rip= */ false)); |
| 1088 | RecordBootImageJniEntrypointPatch(invoke); |
| 1089 | } else { |
| 1090 | // (callee_method + offset_of_jni_entry_point)() |
| 1091 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1092 | ArtMethod::EntryPointFromJniOffset(kX86_64PointerSize).SizeValue())); |
| 1093 | } |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1094 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 1095 | // Zero-/sign-extend the result when needed due to native and managed ABI mismatch. |
| 1096 | switch (invoke->GetType()) { |
| 1097 | case DataType::Type::kBool: |
| 1098 | __ movzxb(CpuRegister(RAX), CpuRegister(RAX)); |
| 1099 | break; |
| 1100 | case DataType::Type::kInt8: |
| 1101 | __ movsxb(CpuRegister(RAX), CpuRegister(RAX)); |
| 1102 | break; |
| 1103 | case DataType::Type::kUint16: |
| 1104 | __ movzxw(CpuRegister(RAX), CpuRegister(RAX)); |
| 1105 | break; |
| 1106 | case DataType::Type::kInt16: |
| 1107 | __ movsxw(CpuRegister(RAX), CpuRegister(RAX)); |
| 1108 | break; |
| 1109 | case DataType::Type::kInt32: |
| 1110 | case DataType::Type::kInt64: |
| 1111 | case DataType::Type::kFloat32: |
| 1112 | case DataType::Type::kFloat64: |
| 1113 | case DataType::Type::kVoid: |
| 1114 | break; |
| 1115 | default: |
| 1116 | DCHECK(false) << invoke->GetType(); |
| 1117 | break; |
| 1118 | } |
| 1119 | if (out_frame_size != 0u) { |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1120 | DecreaseFrame(out_frame_size); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1121 | } |
| 1122 | break; |
| 1123 | } |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 1124 | case CodePtrLocation::kCallArtMethod: |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1125 | // (callee_method + offset_of_quick_compiled_code)() |
| 1126 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1127 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1128 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 1129 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1130 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1131 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1132 | |
| 1133 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1134 | } |
| 1135 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1136 | void CodeGeneratorX86_64::GenerateVirtualCall( |
| 1137 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1138 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1139 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1140 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1141 | |
| 1142 | // Use the calling convention instead of the location of the receiver, as |
| 1143 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1144 | // slow path, the arguments have been moved to the right place, so here we are |
| 1145 | // guaranteed that the receiver is the first register of the calling convention. |
| 1146 | InvokeDexCallingConvention calling_convention; |
| 1147 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1148 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1149 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1150 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1151 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1152 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1153 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1154 | // emit a read barrier for the previous class reference load. |
| 1155 | // However this is not required in practice, as this is an |
| 1156 | // intermediate/temporary reference and because the current |
| 1157 | // concurrent copying collector keeps the from-space memory |
| 1158 | // intact/accessible until the end of the marking phase (the |
| 1159 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1160 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 1161 | |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 1162 | MaybeGenerateInlineCacheCheck(invoke, temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 1163 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1164 | // temp = temp->GetMethodAt(method_offset); |
| 1165 | __ movq(temp, Address(temp, method_offset)); |
| 1166 | // call temp->GetEntryPoint(); |
| 1167 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1168 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1169 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1172 | void CodeGeneratorX86_64::RecordBootImageIntrinsicPatch(uint32_t intrinsic_data) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1173 | boot_image_other_patches_.emplace_back(/* target_dex_file= */ nullptr, intrinsic_data); |
| 1174 | __ Bind(&boot_image_other_patches_.back().label); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1175 | } |
| 1176 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1177 | void CodeGeneratorX86_64::RecordBootImageRelRoPatch(uint32_t boot_image_offset) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1178 | boot_image_other_patches_.emplace_back(/* target_dex_file= */ nullptr, boot_image_offset); |
| 1179 | __ Bind(&boot_image_other_patches_.back().label); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 1182 | void CodeGeneratorX86_64::RecordBootImageMethodPatch(HInvoke* invoke) { |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1183 | boot_image_method_patches_.emplace_back(invoke->GetResolvedMethodReference().dex_file, |
| 1184 | invoke->GetResolvedMethodReference().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1185 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 1188 | void CodeGeneratorX86_64::RecordMethodBssEntryPatch(HInvoke* invoke) { |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1189 | DCHECK(IsSameDexFile(GetGraph()->GetDexFile(), *invoke->GetMethodReference().dex_file)); |
| 1190 | method_bss_entry_patches_.emplace_back(invoke->GetMethodReference().dex_file, |
| 1191 | invoke->GetMethodReference().index); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1192 | __ Bind(&method_bss_entry_patches_.back().label); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1193 | } |
| 1194 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1195 | void CodeGeneratorX86_64::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 1196 | boot_image_type_patches_.emplace_back( |
| 1197 | &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1198 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1199 | } |
| 1200 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1201 | Label* CodeGeneratorX86_64::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1202 | ArenaDeque<PatchInfo<Label>>* patches = nullptr; |
| 1203 | switch (load_class->GetLoadKind()) { |
| 1204 | case HLoadClass::LoadKind::kBssEntry: |
| 1205 | patches = &type_bss_entry_patches_; |
| 1206 | break; |
| 1207 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 1208 | patches = &public_type_bss_entry_patches_; |
| 1209 | break; |
| 1210 | case HLoadClass::LoadKind::kBssEntryPackage: |
| 1211 | patches = &package_type_bss_entry_patches_; |
| 1212 | break; |
| 1213 | default: |
| 1214 | LOG(FATAL) << "Unexpected load kind: " << load_class->GetLoadKind(); |
| 1215 | UNREACHABLE(); |
| 1216 | } |
| 1217 | patches->emplace_back(&load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| 1218 | return &patches->back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1221 | void CodeGeneratorX86_64::RecordBootImageStringPatch(HLoadString* load_string) { |
| 1222 | boot_image_string_patches_.emplace_back( |
| 1223 | &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 1224 | __ Bind(&boot_image_string_patches_.back().label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1225 | } |
| 1226 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1227 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1228 | string_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1229 | &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1230 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1231 | } |
| 1232 | |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1233 | void CodeGeneratorX86_64::RecordBootImageJniEntrypointPatch(HInvokeStaticOrDirect* invoke) { |
| 1234 | boot_image_jni_entrypoint_patches_.emplace_back(invoke->GetResolvedMethodReference().dex_file, |
| 1235 | invoke->GetResolvedMethodReference().index); |
| 1236 | __ Bind(&boot_image_jni_entrypoint_patches_.back().label); |
| 1237 | } |
| 1238 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1239 | void CodeGeneratorX86_64::LoadBootImageAddress(CpuRegister reg, uint32_t boot_image_reference) { |
| 1240 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 1241 | __ leal(reg, |
| 1242 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1243 | RecordBootImageIntrinsicPatch(boot_image_reference); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 1244 | } else if (GetCompilerOptions().GetCompilePic()) { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 1245 | __ movl(reg, |
| 1246 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1247 | RecordBootImageRelRoPatch(boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1248 | } else { |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 1249 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1250 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1251 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1252 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1253 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 1254 | } |
| 1255 | } |
| 1256 | |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 1257 | void CodeGeneratorX86_64::LoadIntrinsicDeclaringClass(CpuRegister reg, HInvoke* invoke) { |
| 1258 | DCHECK_NE(invoke->GetIntrinsic(), Intrinsics::kNone); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1259 | if (GetCompilerOptions().IsBootImage()) { |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1260 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 1261 | __ leal(reg, |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 1262 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Nicolas Geoffray | e6c0f2a | 2020-09-07 08:30:52 +0100 | [diff] [blame] | 1263 | MethodReference target_method = invoke->GetResolvedMethodReference(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1264 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 1265 | boot_image_type_patches_.emplace_back(target_method.dex_file, type_idx.index_); |
| 1266 | __ Bind(&boot_image_type_patches_.back().label); |
| 1267 | } else { |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 1268 | uint32_t boot_image_offset = GetBootImageOffsetOfIntrinsicDeclaringClass(invoke); |
| 1269 | LoadBootImageAddress(reg, boot_image_offset); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1270 | } |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1271 | } |
| 1272 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1273 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 1274 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 1275 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 1276 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1277 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1278 | inline void CodeGeneratorX86_64::EmitPcRelativeLinkerPatches( |
| 1279 | const ArenaDeque<PatchInfo<Label>>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1280 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1281 | for (const PatchInfo<Label>& info : infos) { |
| 1282 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1283 | linker_patches->push_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1284 | 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] | 1285 | } |
| 1286 | } |
| 1287 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1288 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 1289 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 1290 | const DexFile* target_dex_file, |
| 1291 | uint32_t pc_insn_offset, |
| 1292 | uint32_t boot_image_offset) { |
| 1293 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 1294 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1297 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1298 | DCHECK(linker_patches->empty()); |
| 1299 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1300 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1301 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1302 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1303 | type_bss_entry_patches_.size() + |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1304 | public_type_bss_entry_patches_.size() + |
| 1305 | package_type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1306 | boot_image_string_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1307 | string_bss_entry_patches_.size() + |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1308 | boot_image_jni_entrypoint_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1309 | boot_image_other_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1310 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 1311 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1312 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1313 | boot_image_method_patches_, linker_patches); |
| 1314 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1315 | boot_image_type_patches_, linker_patches); |
| 1316 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1317 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1318 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1319 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1320 | DCHECK(boot_image_type_patches_.empty()); |
| 1321 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1322 | } |
| 1323 | if (GetCompilerOptions().IsBootImage()) { |
| 1324 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 1325 | boot_image_other_patches_, linker_patches); |
| 1326 | } else { |
| 1327 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 1328 | boot_image_other_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1329 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1330 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1331 | method_bss_entry_patches_, linker_patches); |
| 1332 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1333 | type_bss_entry_patches_, linker_patches); |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 1334 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PublicTypeBssEntryPatch>( |
| 1335 | public_type_bss_entry_patches_, linker_patches); |
| 1336 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::PackageTypeBssEntryPatch>( |
| 1337 | package_type_bss_entry_patches_, linker_patches); |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1338 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1339 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1340 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeJniEntrypointPatch>( |
| 1341 | boot_image_jni_entrypoint_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1342 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1345 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1346 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1350 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1351 | } |
| 1352 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1353 | const X86_64InstructionSetFeatures& CodeGeneratorX86_64::GetInstructionSetFeatures() const { |
| 1354 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86_64InstructionSetFeatures(); |
| 1355 | } |
| 1356 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1357 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1358 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1359 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1360 | } |
| 1361 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1362 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1363 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1364 | return kX86_64WordSize; |
| 1365 | } |
| 1366 | |
| 1367 | 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] | 1368 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1369 | __ movups(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1370 | } else { |
| 1371 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1372 | } |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1373 | return GetSlowPathFPWidth(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | 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] | 1377 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1378 | __ movups(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1379 | } else { |
| 1380 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1381 | } |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1382 | return GetSlowPathFPWidth(); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1383 | } |
| 1384 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1385 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1386 | HInstruction* instruction, |
| 1387 | uint32_t dex_pc, |
| 1388 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1389 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1390 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1391 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1392 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1393 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1394 | } |
| 1395 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1396 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1397 | HInstruction* instruction, |
| 1398 | SlowPathCode* slow_path) { |
| 1399 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1400 | GenerateInvokeRuntime(entry_point_offset); |
| 1401 | } |
| 1402 | |
| 1403 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1404 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip= */ true)); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1405 | } |
| 1406 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1407 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1408 | // Use a fake return address register to mimic Quick. |
| 1409 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1410 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1411 | const CompilerOptions& compiler_options, |
| 1412 | OptimizingCompilerStats* stats) |
Vladimir Marko | eb9eb00 | 2020-10-02 13:54:19 +0100 | [diff] [blame] | 1413 | : CodeGenerator(graph, |
| 1414 | kNumberOfCpuRegisters, |
| 1415 | kNumberOfFloatRegisters, |
| 1416 | kNumberOfCpuRegisterPairs, |
| 1417 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1418 | arraysize(kCoreCalleeSaves)) |
| 1419 | | (1 << kFakeReturnRegister), |
| 1420 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1421 | arraysize(kFpuCalleeSaves)), |
| 1422 | compiler_options, |
| 1423 | stats), |
| 1424 | block_labels_(nullptr), |
| 1425 | location_builder_(graph, this), |
| 1426 | instruction_visitor_(graph, this), |
| 1427 | move_resolver_(graph->GetAllocator(), this), |
| 1428 | assembler_(graph->GetAllocator()), |
| 1429 | constant_area_start_(0), |
| 1430 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1431 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1432 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1433 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1434 | public_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1435 | package_type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1436 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1437 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1438 | boot_image_jni_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1439 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1440 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1441 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1442 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1443 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1444 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1445 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1446 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1447 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1448 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1449 | assembler_(codegen->GetAssembler()), |
| 1450 | codegen_(codegen) {} |
| 1451 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1452 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1453 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1454 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1455 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1456 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1457 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1458 | } |
| 1459 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1460 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1461 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1462 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1463 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1464 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1465 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1466 | } |
| 1467 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1468 | void CodeGeneratorX86_64::MaybeIncrementHotness(bool is_frame_entry) { |
| 1469 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1470 | NearLabel overflow; |
| 1471 | Register method = kMethodRegisterArgument; |
| 1472 | if (!is_frame_entry) { |
| 1473 | CHECK(RequiresCurrentMethod()); |
| 1474 | method = TMP; |
| 1475 | __ movq(CpuRegister(method), Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 1476 | } |
| 1477 | __ cmpw(Address(CpuRegister(method), ArtMethod::HotnessCountOffset().Int32Value()), |
| 1478 | Immediate(ArtMethod::MaxCounter())); |
| 1479 | __ j(kEqual, &overflow); |
| 1480 | __ addw(Address(CpuRegister(method), ArtMethod::HotnessCountOffset().Int32Value()), |
| 1481 | Immediate(1)); |
| 1482 | __ Bind(&overflow); |
| 1483 | } |
| 1484 | |
| 1485 | if (GetGraph()->IsCompilingBaseline() && !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 1486 | ScopedProfilingInfoUse spiu( |
| 1487 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 1488 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1489 | if (info != nullptr) { |
| 1490 | uint64_t address = reinterpret_cast64<uint64_t>(info); |
| 1491 | NearLabel done; |
| 1492 | __ movq(CpuRegister(TMP), Immediate(address)); |
| 1493 | __ addw(Address(CpuRegister(TMP), ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), |
| 1494 | Immediate(1)); |
Nicolas Geoffray | 4313ccb | 2020-08-26 17:01:15 +0100 | [diff] [blame] | 1495 | __ andw(Address(CpuRegister(TMP), ProfilingInfo::BaselineHotnessCountOffset().Int32Value()), |
| 1496 | Immediate(interpreter::kTieredHotnessMask)); |
| 1497 | __ j(kNotZero, &done); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 1498 | if (HasEmptyFrame()) { |
| 1499 | CHECK(is_frame_entry); |
| 1500 | // Frame alignment, and the stub expects the method on the stack. |
| 1501 | __ pushq(CpuRegister(RDI)); |
| 1502 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1503 | __ cfi().RelOffset(DWARFReg(RDI), 0); |
| 1504 | } else if (!RequiresCurrentMethod()) { |
| 1505 | CHECK(is_frame_entry); |
| 1506 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), CpuRegister(RDI)); |
| 1507 | } |
| 1508 | GenerateInvokeRuntime( |
| 1509 | GetThreadOffset<kX86_64PointerSize>(kQuickCompileOptimized).Int32Value()); |
| 1510 | if (HasEmptyFrame()) { |
| 1511 | __ popq(CpuRegister(RDI)); |
| 1512 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1513 | __ cfi().Restore(DWARFReg(RDI)); |
| 1514 | } |
| 1515 | __ Bind(&done); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1516 | } |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1517 | } |
| 1518 | } |
| 1519 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1520 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1521 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1522 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1523 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1524 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1525 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1526 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1527 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1528 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1529 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86_64); |
| 1530 | __ testq(CpuRegister(RAX), Address(CpuRegister(RSP), -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1531 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1532 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1533 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1534 | if (!HasEmptyFrame()) { |
| 1535 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 1536 | Register reg = kCoreCalleeSaves[i]; |
| 1537 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1538 | __ pushq(CpuRegister(reg)); |
| 1539 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1540 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| 1541 | } |
| 1542 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1543 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1544 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1545 | IncreaseFrame(adjust); |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1546 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1547 | size_t xmm_spill_slot_size = GetCalleePreservedFPWidth(); |
| 1548 | |
| 1549 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1550 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1551 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1552 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1553 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | // Save the current method if we need it. Note that we do not |
| 1558 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1559 | // in the SSA graph. |
| 1560 | if (RequiresCurrentMethod()) { |
| 1561 | CHECK(!HasEmptyFrame()); |
| 1562 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1563 | CpuRegister(kMethodRegisterArgument)); |
| 1564 | } |
| 1565 | |
| 1566 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1567 | CHECK(!HasEmptyFrame()); |
| 1568 | // Initialize should_deoptimize flag to 0. |
| 1569 | __ movl(Address(CpuRegister(RSP), GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1570 | } |
| 1571 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1572 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1573 | MaybeIncrementHotness(/* is_frame_entry= */ true); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1577 | __ cfi().RememberState(); |
| 1578 | if (!HasEmptyFrame()) { |
| 1579 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1580 | size_t xmm_spill_slot_size = GetCalleePreservedFPWidth(); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1581 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1582 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1583 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1584 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1585 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 1590 | DecreaseFrame(adjust); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1591 | |
| 1592 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1593 | Register reg = kCoreCalleeSaves[i]; |
| 1594 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1595 | __ popq(CpuRegister(reg)); |
| 1596 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1597 | __ cfi().Restore(DWARFReg(reg)); |
| 1598 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1599 | } |
| 1600 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1601 | __ ret(); |
| 1602 | __ cfi().RestoreState(); |
| 1603 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1604 | } |
| 1605 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1606 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1607 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1608 | } |
| 1609 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1610 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1611 | if (source.Equals(destination)) { |
| 1612 | return; |
| 1613 | } |
| 1614 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1615 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1616 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1617 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1618 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1619 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1620 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1621 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1622 | } else if (source.IsConstant()) { |
| 1623 | HConstant* constant = source.GetConstant(); |
| 1624 | if (constant->IsLongConstant()) { |
| 1625 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1626 | } else { |
| 1627 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1628 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1629 | } else { |
| 1630 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1631 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1632 | } |
| 1633 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1634 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1635 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1636 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1637 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1638 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1639 | } else if (source.IsConstant()) { |
| 1640 | HConstant* constant = source.GetConstant(); |
| 1641 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1642 | if (constant->IsFloatConstant()) { |
| 1643 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1644 | } else { |
| 1645 | Load64BitValue(dest, value); |
| 1646 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1647 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1648 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1649 | } else { |
| 1650 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1651 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1652 | } |
| 1653 | } else if (destination.IsStackSlot()) { |
| 1654 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1655 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1656 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1657 | } else if (source.IsFpuRegister()) { |
| 1658 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1659 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1660 | } else if (source.IsConstant()) { |
| 1661 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1662 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1663 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1664 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1665 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1666 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1667 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1668 | } |
| 1669 | } else { |
| 1670 | DCHECK(destination.IsDoubleStackSlot()); |
| 1671 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1672 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1673 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1674 | } else if (source.IsFpuRegister()) { |
| 1675 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1676 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1677 | } else if (source.IsConstant()) { |
| 1678 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1679 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1680 | int64_t value = GetInt64ValueOf(constant); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1681 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1682 | } else { |
| 1683 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1684 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1685 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | } |
| 1689 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1690 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1691 | DCHECK(location.IsRegister()); |
| 1692 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1693 | } |
| 1694 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1695 | void CodeGeneratorX86_64::MoveLocation( |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1696 | Location dst, Location src, DataType::Type dst_type ATTRIBUTE_UNUSED) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1697 | Move(dst, src); |
| 1698 | } |
| 1699 | |
| 1700 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1701 | if (location.IsRegister()) { |
| 1702 | locations->AddTemp(location); |
| 1703 | } else { |
| 1704 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1705 | } |
| 1706 | } |
| 1707 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1708 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1709 | if (successor->IsExitBlock()) { |
| 1710 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1711 | return; // no code needed |
| 1712 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1713 | |
| 1714 | HBasicBlock* block = got->GetBlock(); |
| 1715 | HInstruction* previous = got->GetPrevious(); |
| 1716 | |
| 1717 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1718 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 1719 | codegen_->MaybeIncrementHotness(/* is_frame_entry= */ false); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1720 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1721 | return; |
| 1722 | } |
| 1723 | |
| 1724 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1725 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1726 | } |
| 1727 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1728 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1729 | } |
| 1730 | } |
| 1731 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1732 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1733 | got->SetLocations(nullptr); |
| 1734 | } |
| 1735 | |
| 1736 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1737 | HandleGoto(got, got->GetSuccessor()); |
| 1738 | } |
| 1739 | |
| 1740 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1741 | try_boundary->SetLocations(nullptr); |
| 1742 | } |
| 1743 | |
| 1744 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1745 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1746 | if (!successor->IsExitBlock()) { |
| 1747 | HandleGoto(try_boundary, successor); |
| 1748 | } |
| 1749 | } |
| 1750 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1751 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1752 | exit->SetLocations(nullptr); |
| 1753 | } |
| 1754 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1755 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1756 | } |
| 1757 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1758 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1759 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1760 | LabelType* true_label, |
| 1761 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1762 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1763 | __ j(kUnordered, true_label); |
| 1764 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1765 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1766 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1767 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1768 | } |
| 1769 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1770 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1771 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1772 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1773 | Location left = locations->InAt(0); |
| 1774 | Location right = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1775 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1776 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1777 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1778 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1779 | case DataType::Type::kInt8: |
| 1780 | case DataType::Type::kUint16: |
| 1781 | case DataType::Type::kInt16: |
| 1782 | case DataType::Type::kInt32: |
| 1783 | case DataType::Type::kReference: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1784 | codegen_->GenerateIntCompare(left, right); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1785 | break; |
| 1786 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1787 | case DataType::Type::kInt64: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1788 | codegen_->GenerateLongCompare(left, right); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1789 | break; |
| 1790 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1791 | case DataType::Type::kFloat32: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1792 | if (right.IsFpuRegister()) { |
| 1793 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1794 | } else if (right.IsConstant()) { |
| 1795 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1796 | codegen_->LiteralFloatAddress( |
| 1797 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1798 | } else { |
| 1799 | DCHECK(right.IsStackSlot()); |
| 1800 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1801 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1802 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1803 | break; |
| 1804 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1805 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1806 | if (right.IsFpuRegister()) { |
| 1807 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1808 | } else if (right.IsConstant()) { |
| 1809 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1810 | codegen_->LiteralDoubleAddress( |
| 1811 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1812 | } else { |
| 1813 | DCHECK(right.IsDoubleStackSlot()); |
| 1814 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1815 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1816 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1817 | break; |
| 1818 | } |
| 1819 | default: |
| 1820 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | template<class LabelType> |
| 1825 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1826 | LabelType* true_target_in, |
| 1827 | LabelType* false_target_in) { |
| 1828 | // Generated branching requires both targets to be explicit. If either of the |
| 1829 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1830 | LabelType fallthrough_target; |
| 1831 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1832 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1833 | |
| 1834 | // Generate the comparison to set the CC. |
| 1835 | GenerateCompareTest(condition); |
| 1836 | |
| 1837 | // Now generate the correct jump(s). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1838 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1839 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1840 | case DataType::Type::kInt64: { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1841 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1842 | break; |
| 1843 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1844 | case DataType::Type::kFloat32: { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1845 | GenerateFPJumps(condition, true_target, false_target); |
| 1846 | break; |
| 1847 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1848 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1849 | GenerateFPJumps(condition, true_target, false_target); |
| 1850 | break; |
| 1851 | } |
| 1852 | default: |
| 1853 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1854 | } |
| 1855 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1856 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1857 | __ jmp(false_target); |
| 1858 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1859 | |
| 1860 | if (fallthrough_target.IsLinked()) { |
| 1861 | __ Bind(&fallthrough_target); |
| 1862 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1863 | } |
| 1864 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1865 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1866 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1867 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1868 | // conditions if they are materialized due to the complex branching. |
| 1869 | return cond->IsCondition() && |
| 1870 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1871 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1874 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1875 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1876 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1877 | LabelType* true_target, |
| 1878 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1879 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1880 | |
| 1881 | if (true_target == nullptr && false_target == nullptr) { |
| 1882 | // Nothing to do. The code always falls through. |
| 1883 | return; |
| 1884 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1885 | // Constant condition, statically compared against "true" (integer value 1). |
| 1886 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1887 | if (true_target != nullptr) { |
| 1888 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1889 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1890 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1891 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1892 | if (false_target != nullptr) { |
| 1893 | __ jmp(false_target); |
| 1894 | } |
| 1895 | } |
| 1896 | return; |
| 1897 | } |
| 1898 | |
| 1899 | // The following code generates these patterns: |
| 1900 | // (1) true_target == nullptr && false_target != nullptr |
| 1901 | // - opposite condition true => branch to false_target |
| 1902 | // (2) true_target != nullptr && false_target == nullptr |
| 1903 | // - condition true => branch to true_target |
| 1904 | // (3) true_target != nullptr && false_target != nullptr |
| 1905 | // - condition true => branch to true_target |
| 1906 | // - branch to false_target |
| 1907 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1908 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1909 | if (true_target == nullptr) { |
| 1910 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1911 | } else { |
| 1912 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1913 | } |
| 1914 | } else { |
| 1915 | // Materialized condition, compare against 0. |
| 1916 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1917 | if (lhs.IsRegister()) { |
| 1918 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1919 | } else { |
| 1920 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1921 | } |
| 1922 | if (true_target == nullptr) { |
| 1923 | __ j(kEqual, false_target); |
| 1924 | } else { |
| 1925 | __ j(kNotEqual, true_target); |
| 1926 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1927 | } |
| 1928 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1929 | // Condition has not been materialized, use its inputs as the |
| 1930 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1931 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1932 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1933 | // If this is a long or FP comparison that has been folded into |
| 1934 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1935 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1936 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1937 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1938 | return; |
| 1939 | } |
| 1940 | |
| 1941 | Location lhs = condition->GetLocations()->InAt(0); |
| 1942 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1943 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1944 | if (true_target == nullptr) { |
| 1945 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1946 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1947 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1948 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1949 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1950 | |
| 1951 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1952 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1953 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1954 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1955 | } |
| 1956 | } |
| 1957 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1958 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1959 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1960 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1961 | locations->SetInAt(0, Location::Any()); |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1966 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1967 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1968 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1969 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1970 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1971 | nullptr : codegen_->GetLabelOf(false_successor); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1972 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1976 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1977 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1978 | InvokeRuntimeCallingConvention calling_convention; |
| 1979 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1980 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1981 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1982 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1983 | locations->SetInAt(0, Location::Any()); |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1988 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1989 | GenerateTestAndBranch<Label>(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1990 | /* condition_input_index= */ 0, |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1991 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1992 | /* false_target= */ nullptr); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1993 | } |
| 1994 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1995 | void LocationsBuilderX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1996 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1997 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1998 | locations->SetOut(Location::RequiresRegister()); |
| 1999 | } |
| 2000 | |
| 2001 | void InstructionCodeGeneratorX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2002 | __ movl(flag->GetLocations()->Out().AsRegister<CpuRegister>(), |
| 2003 | Address(CpuRegister(RSP), codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 2004 | } |
| 2005 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2006 | static bool SelectCanUseCMOV(HSelect* select) { |
| 2007 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2008 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2009 | return false; |
| 2010 | } |
| 2011 | |
| 2012 | // A FP condition doesn't generate the single CC that we need. |
| 2013 | HInstruction* condition = select->GetCondition(); |
| 2014 | if (condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2015 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2016 | return false; |
| 2017 | } |
| 2018 | |
| 2019 | // We can generate a CMOV for this Select. |
| 2020 | return true; |
| 2021 | } |
| 2022 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2023 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2024 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2025 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2026 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2027 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2028 | } else { |
| 2029 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2030 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 2031 | if (select->InputAt(1)->IsConstant()) { |
| 2032 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2033 | } else { |
| 2034 | locations->SetInAt(1, Location::Any()); |
| 2035 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2036 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2037 | locations->SetInAt(1, Location::Any()); |
| 2038 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 2039 | } |
| 2040 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 2041 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2042 | } |
| 2043 | locations->SetOut(Location::SameAsFirstInput()); |
| 2044 | } |
| 2045 | |
| 2046 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 2047 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2048 | if (SelectCanUseCMOV(select)) { |
| 2049 | // If both the condition and the source types are integer, we can generate |
| 2050 | // a CMOV to implement Select. |
| 2051 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 2052 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2053 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 2054 | |
| 2055 | HInstruction* select_condition = select->GetCondition(); |
| 2056 | Condition cond = kNotEqual; |
| 2057 | |
| 2058 | // Figure out how to test the 'condition'. |
| 2059 | if (select_condition->IsCondition()) { |
| 2060 | HCondition* condition = select_condition->AsCondition(); |
| 2061 | if (!condition->IsEmittedAtUseSite()) { |
| 2062 | // This was a previously materialized condition. |
| 2063 | // Can we use the existing condition code? |
| 2064 | if (AreEflagsSetFrom(condition, select)) { |
| 2065 | // Materialization was the previous instruction. Condition codes are right. |
| 2066 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 2067 | } else { |
| 2068 | // No, we have to recreate the condition code. |
| 2069 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 2070 | __ testl(cond_reg, cond_reg); |
| 2071 | } |
| 2072 | } else { |
| 2073 | GenerateCompareTest(condition); |
| 2074 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 2075 | } |
| 2076 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 2077 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2078 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 2079 | __ testl(cond_reg, cond_reg); |
| 2080 | } |
| 2081 | |
| 2082 | // If the condition is true, overwrite the output, which already contains false. |
| 2083 | // Generate the correct sized CMOV. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2084 | bool is_64_bit = DataType::Is64BitType(select->GetType()); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 2085 | if (value_true_loc.IsRegister()) { |
| 2086 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 2087 | } else { |
| 2088 | __ cmov(cond, |
| 2089 | value_false, |
| 2090 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 2091 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2092 | } else { |
| 2093 | NearLabel false_target; |
| 2094 | GenerateTestAndBranch<NearLabel>(select, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2095 | /* condition_input_index= */ 2, |
| 2096 | /* true_target= */ nullptr, |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2097 | &false_target); |
| 2098 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 2099 | __ Bind(&false_target); |
| 2100 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2103 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2104 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2105 | } |
| 2106 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 2107 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2108 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
Vladimir Marko | dec7817 | 2020-06-19 15:31:23 +0100 | [diff] [blame] | 2111 | void CodeGeneratorX86_64::IncreaseFrame(size_t adjustment) { |
| 2112 | __ subq(CpuRegister(RSP), Immediate(adjustment)); |
| 2113 | __ cfi().AdjustCFAOffset(adjustment); |
| 2114 | } |
| 2115 | |
| 2116 | void CodeGeneratorX86_64::DecreaseFrame(size_t adjustment) { |
| 2117 | __ addq(CpuRegister(RSP), Immediate(adjustment)); |
| 2118 | __ cfi().AdjustCFAOffset(-adjustment); |
| 2119 | } |
| 2120 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 2121 | void CodeGeneratorX86_64::GenerateNop() { |
| 2122 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2125 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2126 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2127 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2128 | // Handle the long/FP comparisons made in instruction simplification. |
| 2129 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2130 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2131 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2132 | locations->SetInAt(1, Location::Any()); |
| 2133 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2134 | case DataType::Type::kFloat32: |
| 2135 | case DataType::Type::kFloat64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2136 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2137 | locations->SetInAt(1, Location::Any()); |
| 2138 | break; |
| 2139 | default: |
| 2140 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2141 | locations->SetInAt(1, Location::Any()); |
| 2142 | break; |
| 2143 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2144 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2145 | locations->SetOut(Location::RequiresRegister()); |
| 2146 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2147 | } |
| 2148 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2149 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2150 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2151 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2152 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2153 | |
| 2154 | LocationSummary* locations = cond->GetLocations(); |
| 2155 | Location lhs = locations->InAt(0); |
| 2156 | Location rhs = locations->InAt(1); |
| 2157 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 2158 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2159 | |
| 2160 | switch (cond->InputAt(0)->GetType()) { |
| 2161 | default: |
| 2162 | // Integer case. |
| 2163 | |
| 2164 | // Clear output register: setcc only sets the low byte. |
| 2165 | __ xorl(reg, reg); |
| 2166 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2167 | codegen_->GenerateIntCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2168 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2169 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2170 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2171 | // Clear output register: setcc only sets the low byte. |
| 2172 | __ xorl(reg, reg); |
| 2173 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2174 | codegen_->GenerateLongCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2175 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2176 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2177 | case DataType::Type::kFloat32: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2178 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 2179 | if (rhs.IsConstant()) { |
| 2180 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 2181 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 2182 | } else if (rhs.IsStackSlot()) { |
| 2183 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 2184 | } else { |
| 2185 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 2186 | } |
| 2187 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2188 | break; |
| 2189 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2190 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2191 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 2192 | if (rhs.IsConstant()) { |
| 2193 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2194 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 2195 | } else if (rhs.IsDoubleStackSlot()) { |
| 2196 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 2197 | } else { |
| 2198 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 2199 | } |
| 2200 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2201 | break; |
| 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2206 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2207 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2208 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2209 | __ Bind(&false_label); |
| 2210 | __ xorl(reg, reg); |
| 2211 | __ jmp(&done_label); |
| 2212 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2213 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2214 | __ Bind(&true_label); |
| 2215 | __ movl(reg, Immediate(1)); |
| 2216 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2217 | } |
| 2218 | |
| 2219 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2220 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2224 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2228 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2232 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2236 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2240 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2244 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2248 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2252 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2256 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2260 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2264 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2265 | } |
| 2266 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2267 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2268 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2272 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2276 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2280 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2284 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2288 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2292 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2296 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2299 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2300 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2301 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2302 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2303 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2304 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2305 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2306 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2307 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2308 | case DataType::Type::kInt32: |
| 2309 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2310 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2311 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2312 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2313 | break; |
| 2314 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2315 | case DataType::Type::kFloat32: |
| 2316 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2317 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2318 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2319 | locations->SetOut(Location::RequiresRegister()); |
| 2320 | break; |
| 2321 | } |
| 2322 | default: |
| 2323 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2324 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2328 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2329 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2330 | Location left = locations->InAt(0); |
| 2331 | Location right = locations->InAt(1); |
| 2332 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2333 | NearLabel less, greater, done; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2334 | DataType::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2335 | Condition less_cond = kLess; |
| 2336 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2337 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2338 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2339 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2340 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2341 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2342 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2343 | case DataType::Type::kInt32: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2344 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2345 | break; |
| 2346 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2347 | case DataType::Type::kInt64: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2348 | codegen_->GenerateLongCompare(left, right); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2349 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2350 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2351 | case DataType::Type::kFloat32: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2352 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2353 | if (right.IsConstant()) { |
| 2354 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2355 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2356 | } else if (right.IsStackSlot()) { |
| 2357 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2358 | } else { |
| 2359 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2360 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2361 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2362 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2363 | break; |
| 2364 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2365 | case DataType::Type::kFloat64: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2366 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2367 | if (right.IsConstant()) { |
| 2368 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2369 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2370 | } else if (right.IsDoubleStackSlot()) { |
| 2371 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2372 | } else { |
| 2373 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2374 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2375 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2376 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2377 | break; |
| 2378 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2379 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2380 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2381 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2382 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2383 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2384 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2385 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2386 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2387 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2388 | __ movl(out, Immediate(1)); |
| 2389 | __ jmp(&done); |
| 2390 | |
| 2391 | __ Bind(&less); |
| 2392 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2393 | |
| 2394 | __ Bind(&done); |
| 2395 | } |
| 2396 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2397 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2398 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2399 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2400 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2401 | } |
| 2402 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2403 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2404 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2405 | } |
| 2406 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2407 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2408 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2409 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2410 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2411 | } |
| 2412 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2413 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2414 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2417 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2418 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2419 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2420 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2421 | } |
| 2422 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2423 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2424 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2425 | } |
| 2426 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2427 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2428 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2429 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2430 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2431 | } |
| 2432 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2433 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2434 | // Will be generated at use site. |
| 2435 | } |
| 2436 | |
| 2437 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2438 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2439 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2440 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2441 | } |
| 2442 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2443 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2444 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2445 | // Will be generated at use site. |
| 2446 | } |
| 2447 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2448 | void LocationsBuilderX86_64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2449 | constructor_fence->SetLocations(nullptr); |
| 2450 | } |
| 2451 | |
| 2452 | void InstructionCodeGeneratorX86_64::VisitConstructorFence( |
| 2453 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2454 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2455 | } |
| 2456 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2457 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2458 | memory_barrier->SetLocations(nullptr); |
| 2459 | } |
| 2460 | |
| 2461 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2462 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2463 | } |
| 2464 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2465 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2466 | ret->SetLocations(nullptr); |
| 2467 | } |
| 2468 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2469 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2470 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2474 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2475 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2476 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2477 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2478 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2479 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2480 | case DataType::Type::kInt8: |
| 2481 | case DataType::Type::kUint16: |
| 2482 | case DataType::Type::kInt16: |
| 2483 | case DataType::Type::kInt32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2484 | case DataType::Type::kInt64: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2485 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2486 | break; |
| 2487 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2488 | case DataType::Type::kFloat32: |
| 2489 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2490 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2491 | break; |
| 2492 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2493 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2494 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2495 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2499 | switch (ret->InputAt(0)->GetType()) { |
| 2500 | case DataType::Type::kReference: |
| 2501 | case DataType::Type::kBool: |
| 2502 | case DataType::Type::kUint8: |
| 2503 | case DataType::Type::kInt8: |
| 2504 | case DataType::Type::kUint16: |
| 2505 | case DataType::Type::kInt16: |
| 2506 | case DataType::Type::kInt32: |
| 2507 | case DataType::Type::kInt64: |
| 2508 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
| 2509 | break; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2510 | |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2511 | case DataType::Type::kFloat32: { |
| 2512 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
| 2513 | XMM0); |
| 2514 | // To simplify callers of an OSR method, we put the return value in both |
| 2515 | // floating point and core register. |
| 2516 | if (GetGraph()->IsCompilingOsr()) { |
| 2517 | __ movd(CpuRegister(RAX), XmmRegister(XMM0), /* is64bit= */ false); |
| 2518 | } |
| 2519 | break; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2520 | } |
Nicolas Geoffray | 57cacb7 | 2019-12-08 22:07:08 +0000 | [diff] [blame] | 2521 | case DataType::Type::kFloat64: { |
| 2522 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
| 2523 | XMM0); |
| 2524 | // To simplify callers of an OSR method, we put the return value in both |
| 2525 | // floating point and core register. |
| 2526 | if (GetGraph()->IsCompilingOsr()) { |
| 2527 | __ movd(CpuRegister(RAX), XmmRegister(XMM0), /* is64bit= */ true); |
| 2528 | } |
| 2529 | break; |
| 2530 | } |
| 2531 | |
| 2532 | default: |
| 2533 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2534 | } |
| 2535 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2536 | } |
| 2537 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2538 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2539 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2540 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2541 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2542 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2543 | case DataType::Type::kInt8: |
| 2544 | case DataType::Type::kUint16: |
| 2545 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2546 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2547 | case DataType::Type::kInt32: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2548 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2549 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2550 | return Location::RegisterLocation(RAX); |
| 2551 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2552 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2553 | return Location::NoLocation(); |
| 2554 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2555 | case DataType::Type::kFloat64: |
| 2556 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2557 | return Location::FpuRegisterLocation(XMM0); |
| 2558 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2559 | |
| 2560 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2564 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2565 | } |
| 2566 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2567 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2568 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2569 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2570 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2571 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2572 | case DataType::Type::kInt8: |
| 2573 | case DataType::Type::kUint16: |
| 2574 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2575 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2576 | uint32_t index = gp_index_++; |
| 2577 | stack_index_++; |
| 2578 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2579 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2580 | } else { |
| 2581 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2582 | } |
| 2583 | } |
| 2584 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2585 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2586 | uint32_t index = gp_index_; |
| 2587 | stack_index_ += 2; |
| 2588 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2589 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2590 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2591 | } else { |
| 2592 | gp_index_ += 2; |
| 2593 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2594 | } |
| 2595 | } |
| 2596 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2597 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2598 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2599 | stack_index_++; |
| 2600 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2601 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2602 | } else { |
| 2603 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2604 | } |
| 2605 | } |
| 2606 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2607 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2608 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2609 | stack_index_ += 2; |
| 2610 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2611 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2612 | } else { |
| 2613 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2614 | } |
| 2615 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2616 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2617 | case DataType::Type::kUint32: |
| 2618 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2619 | case DataType::Type::kVoid: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2620 | LOG(FATAL) << "Unexpected parameter type " << type; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 2621 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2622 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2623 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2624 | } |
| 2625 | |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2626 | Location CriticalNativeCallingConventionVisitorX86_64::GetNextLocation(DataType::Type type) { |
| 2627 | DCHECK_NE(type, DataType::Type::kReference); |
| 2628 | |
| 2629 | Location location = Location::NoLocation(); |
| 2630 | if (DataType::IsFloatingPointType(type)) { |
| 2631 | if (fpr_index_ < kParameterFloatRegistersLength) { |
| 2632 | location = Location::FpuRegisterLocation(kParameterFloatRegisters[fpr_index_]); |
| 2633 | ++fpr_index_; |
| 2634 | } |
| 2635 | } else { |
| 2636 | // Native ABI uses the same registers as managed, except that the method register RDI |
| 2637 | // is a normal argument. |
| 2638 | if (gpr_index_ < 1u + kParameterCoreRegistersLength) { |
| 2639 | location = Location::RegisterLocation( |
| 2640 | gpr_index_ == 0u ? RDI : kParameterCoreRegisters[gpr_index_ - 1u]); |
| 2641 | ++gpr_index_; |
| 2642 | } |
| 2643 | } |
| 2644 | if (location.IsInvalid()) { |
| 2645 | if (DataType::Is64BitType(type)) { |
| 2646 | location = Location::DoubleStackSlot(stack_offset_); |
| 2647 | } else { |
| 2648 | location = Location::StackSlot(stack_offset_); |
| 2649 | } |
| 2650 | stack_offset_ += kFramePointerSize; |
| 2651 | |
| 2652 | if (for_register_allocation_) { |
| 2653 | location = Location::Any(); |
| 2654 | } |
| 2655 | } |
| 2656 | return location; |
| 2657 | } |
| 2658 | |
| 2659 | Location CriticalNativeCallingConventionVisitorX86_64::GetReturnLocation(DataType::Type type) |
| 2660 | const { |
| 2661 | // We perform conversion to the managed ABI return register after the call if needed. |
| 2662 | InvokeDexCallingConventionVisitorX86_64 dex_calling_convention; |
| 2663 | return dex_calling_convention.GetReturnLocation(type); |
| 2664 | } |
| 2665 | |
| 2666 | Location CriticalNativeCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2667 | // Pass the method in the hidden argument RAX. |
| 2668 | return Location::RegisterLocation(RAX); |
| 2669 | } |
| 2670 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2671 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2672 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2673 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2674 | // the method_idx. |
| 2675 | HandleInvoke(invoke); |
| 2676 | } |
| 2677 | |
| 2678 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2679 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2680 | } |
| 2681 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2682 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2683 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2684 | // art::PrepareForRegisterAllocation. |
| 2685 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2686 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2687 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2688 | if (intrinsic.TryDispatch(invoke)) { |
| 2689 | return; |
| 2690 | } |
| 2691 | |
Nicolas Geoffray | 6d69b52 | 2020-09-23 14:47:28 +0100 | [diff] [blame] | 2692 | if (invoke->GetCodePtrLocation() == CodePtrLocation::kCallCriticalNative) { |
Vladimir Marko | 86c8752 | 2020-05-11 16:55:55 +0100 | [diff] [blame] | 2693 | CriticalNativeCallingConventionVisitorX86_64 calling_convention_visitor( |
| 2694 | /*for_register_allocation=*/ true); |
| 2695 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 2696 | CodeGeneratorX86_64::BlockNonVolatileXmmRegisters(invoke->GetLocations()); |
| 2697 | } else { |
| 2698 | HandleInvoke(invoke); |
| 2699 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2700 | } |
| 2701 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2702 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2703 | if (invoke->GetLocations()->Intrinsified()) { |
| 2704 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2705 | intrinsic.Dispatch(invoke); |
| 2706 | return true; |
| 2707 | } |
| 2708 | return false; |
| 2709 | } |
| 2710 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2711 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2712 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2713 | // art::PrepareForRegisterAllocation. |
| 2714 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2715 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2716 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2717 | return; |
| 2718 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2719 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2720 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2721 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2722 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2723 | } |
| 2724 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2725 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2726 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2727 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2728 | } |
| 2729 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2730 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2731 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2732 | if (intrinsic.TryDispatch(invoke)) { |
| 2733 | return; |
| 2734 | } |
| 2735 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2736 | HandleInvoke(invoke); |
| 2737 | } |
| 2738 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2739 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2740 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2741 | return; |
| 2742 | } |
| 2743 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2744 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2745 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2746 | } |
| 2747 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2748 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2749 | HandleInvoke(invoke); |
| 2750 | // Add the hidden argument. |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2751 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRecursive) { |
| 2752 | invoke->GetLocations()->SetInAt(invoke->GetNumberOfArguments() - 1, |
| 2753 | Location::RegisterLocation(RAX)); |
| 2754 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2755 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2756 | } |
| 2757 | |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 2758 | void CodeGeneratorX86_64::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 2759 | CpuRegister klass) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2760 | DCHECK_EQ(RDI, klass.AsRegister()); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 2761 | // We know the destination of an intrinsic, so no need to record inline |
| 2762 | // caches. |
| 2763 | if (!instruction->GetLocations()->Intrinsified() && |
Nicolas Geoffray | 9b5271e | 2019-12-04 14:39:46 +0000 | [diff] [blame] | 2764 | GetGraph()->IsCompilingBaseline() && |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 2765 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | 095dc46 | 2020-08-17 16:40:28 +0100 | [diff] [blame] | 2766 | ScopedProfilingInfoUse spiu( |
| 2767 | Runtime::Current()->GetJit(), GetGraph()->GetArtMethod(), Thread::Current()); |
| 2768 | ProfilingInfo* info = spiu.GetProfilingInfo(); |
Nicolas Geoffray | 796aa2c | 2019-12-17 10:20:05 +0000 | [diff] [blame] | 2769 | if (info != nullptr) { |
| 2770 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 2771 | uint64_t address = reinterpret_cast64<uint64_t>(cache); |
| 2772 | NearLabel done; |
| 2773 | __ movq(CpuRegister(TMP), Immediate(address)); |
| 2774 | // Fast path for a monomorphic cache. |
| 2775 | __ cmpl(Address(CpuRegister(TMP), InlineCache::ClassesOffset().Int32Value()), klass); |
| 2776 | __ j(kEqual, &done); |
| 2777 | GenerateInvokeRuntime( |
| 2778 | GetThreadOffset<kX86_64PointerSize>(kQuickUpdateInlineCache).Int32Value()); |
| 2779 | __ Bind(&done); |
| 2780 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2781 | } |
| 2782 | } |
| 2783 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2784 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2785 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2786 | LocationSummary* locations = invoke->GetLocations(); |
| 2787 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2788 | Location receiver = locations->InAt(0); |
| 2789 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2790 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2791 | if (receiver.IsStackSlot()) { |
| 2792 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2793 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2794 | __ movl(temp, Address(temp, class_offset)); |
| 2795 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2796 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2797 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2798 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2799 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2800 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2801 | // emit a read barrier for the previous class reference load. |
| 2802 | // However this is not required in practice, as this is an |
| 2803 | // intermediate/temporary reference and because the current |
| 2804 | // concurrent copying collector keeps the from-space memory |
| 2805 | // intact/accessible until the end of the marking phase (the |
| 2806 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2807 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2808 | |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame] | 2809 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2810 | |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame^] | 2811 | if (invoke->GetHiddenArgumentLoadKind() != MethodLoadKind::kRecursive && |
| 2812 | invoke->GetHiddenArgumentLoadKind() != MethodLoadKind::kRuntimeCall) { |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2813 | Location hidden_reg = locations->GetTemp(1); |
| 2814 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2815 | // won't be modified thereafter, before the `call` instruction. |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame^] | 2816 | // We also do it after MaybeGenerateInlineCache that may use RAX. |
Nicolas Geoffray | 8d34a18 | 2020-09-16 09:46:58 +0100 | [diff] [blame] | 2817 | DCHECK_EQ(RAX, hidden_reg.AsRegister<Register>()); |
| 2818 | codegen_->LoadMethod(invoke->GetHiddenArgumentLoadKind(), hidden_reg, invoke); |
| 2819 | } |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2820 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2821 | // temp = temp->GetAddressOfIMT() |
| 2822 | __ movq(temp, |
| 2823 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2824 | // temp = temp->GetImtEntryAt(method_offset); |
| 2825 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2826 | invoke->GetImtIndex(), kX86_64PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2827 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2828 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | d6bd107 | 2020-11-30 18:42:01 +0000 | [diff] [blame^] | 2829 | if (invoke->GetHiddenArgumentLoadKind() == MethodLoadKind::kRuntimeCall) { |
| 2830 | // We pass the method from the IMT in case of a conflict. This will ensure |
| 2831 | // we go into the runtime to resolve the actual method. |
| 2832 | Location hidden_reg = locations->GetTemp(1); |
| 2833 | __ movq(hidden_reg.AsRegister<CpuRegister>(), temp); |
| 2834 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2835 | // call temp->GetEntryPoint(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2836 | __ call(Address( |
| 2837 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2838 | |
| 2839 | DCHECK(!codegen_->IsLeafMethod()); |
| 2840 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2841 | } |
| 2842 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2843 | void LocationsBuilderX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 2844 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| 2845 | if (intrinsic.TryDispatch(invoke)) { |
| 2846 | return; |
| 2847 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2848 | HandleInvoke(invoke); |
| 2849 | } |
| 2850 | |
| 2851 | void InstructionCodeGeneratorX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
Andra Danciu | a0130e8 | 2020-07-23 12:34:56 +0000 | [diff] [blame] | 2852 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2853 | return; |
| 2854 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2855 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2856 | } |
| 2857 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2858 | void LocationsBuilderX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2859 | HandleInvoke(invoke); |
| 2860 | } |
| 2861 | |
| 2862 | void InstructionCodeGeneratorX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2863 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2864 | } |
| 2865 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2866 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2867 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2868 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2869 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2870 | case DataType::Type::kInt32: |
| 2871 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2872 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2873 | locations->SetOut(Location::SameAsFirstInput()); |
| 2874 | break; |
| 2875 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2876 | case DataType::Type::kFloat32: |
| 2877 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2878 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2879 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2880 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2881 | break; |
| 2882 | |
| 2883 | default: |
| 2884 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2889 | LocationSummary* locations = neg->GetLocations(); |
| 2890 | Location out = locations->Out(); |
| 2891 | Location in = locations->InAt(0); |
| 2892 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2893 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2894 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2895 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2896 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2897 | break; |
| 2898 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2899 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2900 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2901 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2902 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2903 | break; |
| 2904 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2905 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2906 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2907 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2908 | // Implement float negation with an exclusive or with value |
| 2909 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2910 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2911 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2912 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2913 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2914 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2915 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2916 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2917 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2918 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2919 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2920 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2921 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2922 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2923 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2924 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2925 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2926 | |
| 2927 | default: |
| 2928 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2929 | } |
| 2930 | } |
| 2931 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2932 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2933 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2934 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2935 | DataType::Type result_type = conversion->GetResultType(); |
| 2936 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2937 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2938 | << input_type << " -> " << result_type; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2939 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2940 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2941 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2942 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2943 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2944 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2945 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2946 | locations->SetInAt(0, Location::Any()); |
| 2947 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2948 | break; |
| 2949 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2950 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2951 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2952 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2953 | locations->SetInAt(0, Location::Any()); |
| 2954 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2955 | break; |
| 2956 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2957 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2958 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2959 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2960 | break; |
| 2961 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2962 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2963 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2964 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2965 | break; |
| 2966 | |
| 2967 | default: |
| 2968 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2969 | << " to " << result_type; |
| 2970 | } |
| 2971 | break; |
| 2972 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2973 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2974 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2975 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2976 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2977 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2978 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2979 | case DataType::Type::kInt16: |
| 2980 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2981 | // TODO: We would benefit from a (to-be-implemented) |
| 2982 | // Location::RegisterOrStackSlot requirement for this input. |
| 2983 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2984 | locations->SetOut(Location::RequiresRegister()); |
| 2985 | break; |
| 2986 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2987 | case DataType::Type::kFloat32: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2988 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2989 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2990 | break; |
| 2991 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2992 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2993 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2994 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2995 | break; |
| 2996 | |
| 2997 | default: |
| 2998 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2999 | << " to " << result_type; |
| 3000 | } |
| 3001 | break; |
| 3002 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3003 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3004 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3005 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3006 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3007 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3008 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3009 | case DataType::Type::kInt16: |
| 3010 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3011 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3012 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3013 | break; |
| 3014 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3015 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3016 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3017 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3018 | break; |
| 3019 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3020 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3021 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3022 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3023 | break; |
| 3024 | |
| 3025 | default: |
| 3026 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3027 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3028 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3029 | break; |
| 3030 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3031 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3032 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3033 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3034 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3035 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3036 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3037 | case DataType::Type::kInt16: |
| 3038 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3039 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3040 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3041 | break; |
| 3042 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3043 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3044 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3045 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3046 | break; |
| 3047 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3048 | case DataType::Type::kFloat32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3049 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 3050 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3051 | break; |
| 3052 | |
| 3053 | default: |
| 3054 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3055 | << " to " << result_type; |
| 3056 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3057 | break; |
| 3058 | |
| 3059 | default: |
| 3060 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3061 | << " to " << result_type; |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 3066 | LocationSummary* locations = conversion->GetLocations(); |
| 3067 | Location out = locations->Out(); |
| 3068 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3069 | DataType::Type result_type = conversion->GetResultType(); |
| 3070 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3071 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3072 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3073 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3074 | case DataType::Type::kUint8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3075 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3076 | case DataType::Type::kInt8: |
| 3077 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3078 | case DataType::Type::kInt16: |
| 3079 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3080 | case DataType::Type::kInt64: |
| 3081 | if (in.IsRegister()) { |
| 3082 | __ movzxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 3083 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 3084 | __ movzxb(out.AsRegister<CpuRegister>(), |
| 3085 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3086 | } else { |
| 3087 | __ movl(out.AsRegister<CpuRegister>(), |
| 3088 | Immediate(static_cast<uint8_t>(Int64FromConstant(in.GetConstant())))); |
| 3089 | } |
| 3090 | break; |
| 3091 | |
| 3092 | default: |
| 3093 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3094 | << " to " << result_type; |
| 3095 | } |
| 3096 | break; |
| 3097 | |
| 3098 | case DataType::Type::kInt8: |
| 3099 | switch (input_type) { |
| 3100 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3101 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3102 | case DataType::Type::kInt16: |
| 3103 | case DataType::Type::kInt32: |
| 3104 | case DataType::Type::kInt64: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3105 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3106 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3107 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3108 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3109 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3110 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3111 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3112 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 3113 | } |
| 3114 | break; |
| 3115 | |
| 3116 | default: |
| 3117 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3118 | << " to " << result_type; |
| 3119 | } |
| 3120 | break; |
| 3121 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3122 | case DataType::Type::kUint16: |
| 3123 | switch (input_type) { |
| 3124 | case DataType::Type::kInt8: |
| 3125 | case DataType::Type::kInt16: |
| 3126 | case DataType::Type::kInt32: |
| 3127 | case DataType::Type::kInt64: |
| 3128 | if (in.IsRegister()) { |
| 3129 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 3130 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 3131 | __ movzxw(out.AsRegister<CpuRegister>(), |
| 3132 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3133 | } else { |
| 3134 | __ movl(out.AsRegister<CpuRegister>(), |
| 3135 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
| 3136 | } |
| 3137 | break; |
| 3138 | |
| 3139 | default: |
| 3140 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3141 | << " to " << result_type; |
| 3142 | } |
| 3143 | break; |
| 3144 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3145 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3146 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3147 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3148 | case DataType::Type::kInt32: |
| 3149 | case DataType::Type::kInt64: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3150 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3151 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3152 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3153 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3154 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3155 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3156 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 3157 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 3158 | } |
| 3159 | break; |
| 3160 | |
| 3161 | default: |
| 3162 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3163 | << " to " << result_type; |
| 3164 | } |
| 3165 | break; |
| 3166 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3167 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3168 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3169 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3170 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3171 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3172 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3173 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3174 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3175 | } else { |
| 3176 | DCHECK(in.IsConstant()); |
| 3177 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 3178 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3179 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3180 | } |
| 3181 | break; |
| 3182 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3183 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3184 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3185 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3186 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3187 | |
| 3188 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 3189 | // if input >= (float)INT_MAX goto done |
Nick Desaulniers | 98e97c6 | 2019-10-18 14:25:19 -0700 | [diff] [blame] | 3190 | __ comiss(input, codegen_->LiteralFloatAddress(static_cast<float>(kPrimIntMax))); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3191 | __ j(kAboveEqual, &done); |
| 3192 | // if input == NaN goto nan |
| 3193 | __ j(kUnordered, &nan); |
| 3194 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3195 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 3196 | __ jmp(&done); |
| 3197 | __ Bind(&nan); |
| 3198 | // output = 0 |
| 3199 | __ xorl(output, output); |
| 3200 | __ Bind(&done); |
| 3201 | break; |
| 3202 | } |
| 3203 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3204 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3205 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3206 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3207 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3208 | |
| 3209 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 3210 | // if input >= (double)INT_MAX goto done |
| 3211 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3212 | __ j(kAboveEqual, &done); |
| 3213 | // if input == NaN goto nan |
| 3214 | __ j(kUnordered, &nan); |
| 3215 | // output = double-to-int-truncate(input) |
| 3216 | __ cvttsd2si(output, input); |
| 3217 | __ jmp(&done); |
| 3218 | __ Bind(&nan); |
| 3219 | // output = 0 |
| 3220 | __ xorl(output, output); |
| 3221 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3222 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3223 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 3224 | |
| 3225 | default: |
| 3226 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3227 | << " to " << result_type; |
| 3228 | } |
| 3229 | break; |
| 3230 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3231 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3232 | switch (input_type) { |
| 3233 | DCHECK(out.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3234 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3235 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3236 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3237 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3238 | case DataType::Type::kInt16: |
| 3239 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3240 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3241 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3242 | break; |
| 3243 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3244 | case DataType::Type::kFloat32: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3245 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3246 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3247 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3248 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3249 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 3250 | // if input >= (float)LONG_MAX goto done |
Nick Desaulniers | 98e97c6 | 2019-10-18 14:25:19 -0700 | [diff] [blame] | 3251 | __ comiss(input, codegen_->LiteralFloatAddress(static_cast<float>(kPrimLongMax))); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3252 | __ j(kAboveEqual, &done); |
| 3253 | // if input == NaN goto nan |
| 3254 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3255 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3256 | __ cvttss2si(output, input, true); |
| 3257 | __ jmp(&done); |
| 3258 | __ Bind(&nan); |
| 3259 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3260 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3261 | __ Bind(&done); |
| 3262 | break; |
| 3263 | } |
| 3264 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3265 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3266 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3267 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3268 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3269 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3270 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 3271 | // if input >= (double)LONG_MAX goto done |
Nick Desaulniers | 98e97c6 | 2019-10-18 14:25:19 -0700 | [diff] [blame] | 3272 | __ comisd(input, codegen_->LiteralDoubleAddress( |
| 3273 | static_cast<double>(kPrimLongMax))); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3274 | __ j(kAboveEqual, &done); |
| 3275 | // if input == NaN goto nan |
| 3276 | __ j(kUnordered, &nan); |
| 3277 | // output = double-to-long-truncate(input) |
| 3278 | __ cvttsd2si(output, input, true); |
| 3279 | __ jmp(&done); |
| 3280 | __ Bind(&nan); |
| 3281 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3282 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3283 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3284 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3285 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3286 | |
| 3287 | default: |
| 3288 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3289 | << " to " << result_type; |
| 3290 | } |
| 3291 | break; |
| 3292 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3293 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3294 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3295 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3296 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3297 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3298 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3299 | case DataType::Type::kInt16: |
| 3300 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3301 | if (in.IsRegister()) { |
| 3302 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3303 | } else if (in.IsConstant()) { |
| 3304 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3305 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3306 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3307 | } else { |
| 3308 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3309 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3310 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3311 | break; |
| 3312 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3313 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3314 | if (in.IsRegister()) { |
| 3315 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3316 | } else if (in.IsConstant()) { |
| 3317 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3318 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 3319 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3320 | } else { |
| 3321 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3322 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3323 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3324 | break; |
| 3325 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3326 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3327 | if (in.IsFpuRegister()) { |
| 3328 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3329 | } else if (in.IsConstant()) { |
| 3330 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 3331 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3332 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3333 | } else { |
| 3334 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 3335 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3336 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3337 | break; |
| 3338 | |
| 3339 | default: |
| 3340 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3341 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3342 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3343 | break; |
| 3344 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3345 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3346 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3347 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3348 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3349 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3350 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3351 | case DataType::Type::kInt16: |
| 3352 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3353 | if (in.IsRegister()) { |
| 3354 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3355 | } else if (in.IsConstant()) { |
| 3356 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3357 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3358 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3359 | } else { |
| 3360 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3361 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3362 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3363 | break; |
| 3364 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3365 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3366 | if (in.IsRegister()) { |
| 3367 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3368 | } else if (in.IsConstant()) { |
| 3369 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3370 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3371 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3372 | } else { |
| 3373 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3374 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3375 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3376 | break; |
| 3377 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3378 | case DataType::Type::kFloat32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3379 | if (in.IsFpuRegister()) { |
| 3380 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3381 | } else if (in.IsConstant()) { |
| 3382 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3383 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3384 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3385 | } else { |
| 3386 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3387 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3388 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3389 | break; |
| 3390 | |
| 3391 | default: |
| 3392 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3393 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3394 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3395 | break; |
| 3396 | |
| 3397 | default: |
| 3398 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3399 | << " to " << result_type; |
| 3400 | } |
| 3401 | } |
| 3402 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3403 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3404 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3405 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3406 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3407 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3408 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3409 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3410 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3411 | break; |
| 3412 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3413 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3414 | case DataType::Type::kInt64: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3415 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3416 | // 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] | 3417 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3418 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3419 | break; |
| 3420 | } |
| 3421 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3422 | case DataType::Type::kFloat64: |
| 3423 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3424 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3425 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3426 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3427 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3428 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3429 | |
| 3430 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3431 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3432 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3433 | } |
| 3434 | |
| 3435 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3436 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3437 | Location first = locations->InAt(0); |
| 3438 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3439 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3440 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3441 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3442 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3443 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3444 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3445 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3446 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3447 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3448 | } else { |
| 3449 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3450 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3451 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3452 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3453 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3454 | __ addl(out.AsRegister<CpuRegister>(), |
| 3455 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3456 | } else { |
| 3457 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3458 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3459 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3460 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3461 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3462 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3463 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3464 | break; |
| 3465 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3466 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3467 | case DataType::Type::kInt64: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3468 | if (second.IsRegister()) { |
| 3469 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3470 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3471 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3472 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3473 | } else { |
| 3474 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3475 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3476 | } |
| 3477 | } else { |
| 3478 | DCHECK(second.IsConstant()); |
| 3479 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3480 | int32_t int32_value = Low32Bits(value); |
| 3481 | DCHECK_EQ(int32_value, value); |
| 3482 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3483 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3484 | } else { |
| 3485 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3486 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3487 | } |
| 3488 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3489 | break; |
| 3490 | } |
| 3491 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3492 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3493 | if (second.IsFpuRegister()) { |
| 3494 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3495 | } else if (second.IsConstant()) { |
| 3496 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3497 | codegen_->LiteralFloatAddress( |
| 3498 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3499 | } else { |
| 3500 | DCHECK(second.IsStackSlot()); |
| 3501 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3502 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3503 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3504 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3505 | } |
| 3506 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3507 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3508 | if (second.IsFpuRegister()) { |
| 3509 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3510 | } else if (second.IsConstant()) { |
| 3511 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3512 | codegen_->LiteralDoubleAddress( |
| 3513 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3514 | } else { |
| 3515 | DCHECK(second.IsDoubleStackSlot()); |
| 3516 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3517 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3518 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3519 | break; |
| 3520 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3521 | |
| 3522 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3523 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3524 | } |
| 3525 | } |
| 3526 | |
| 3527 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3528 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3529 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3530 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3531 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3532 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3533 | locations->SetInAt(1, Location::Any()); |
| 3534 | locations->SetOut(Location::SameAsFirstInput()); |
| 3535 | break; |
| 3536 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3537 | case DataType::Type::kInt64: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3538 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3539 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3540 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3541 | break; |
| 3542 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3543 | case DataType::Type::kFloat32: |
| 3544 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3545 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3546 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3547 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3548 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3549 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3550 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3551 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3552 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3556 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3557 | Location first = locations->InAt(0); |
| 3558 | Location second = locations->InAt(1); |
| 3559 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3560 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3561 | case DataType::Type::kInt32: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3562 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3563 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3564 | } else if (second.IsConstant()) { |
| 3565 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3566 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3567 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3568 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3569 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3570 | break; |
| 3571 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3572 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3573 | if (second.IsConstant()) { |
| 3574 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3575 | DCHECK(IsInt<32>(value)); |
| 3576 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3577 | } else { |
| 3578 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3579 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3580 | break; |
| 3581 | } |
| 3582 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3583 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3584 | if (second.IsFpuRegister()) { |
| 3585 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3586 | } else if (second.IsConstant()) { |
| 3587 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3588 | codegen_->LiteralFloatAddress( |
| 3589 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3590 | } else { |
| 3591 | DCHECK(second.IsStackSlot()); |
| 3592 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3593 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3594 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3595 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3596 | } |
| 3597 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3598 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3599 | if (second.IsFpuRegister()) { |
| 3600 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3601 | } else if (second.IsConstant()) { |
| 3602 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3603 | codegen_->LiteralDoubleAddress( |
| 3604 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3605 | } else { |
| 3606 | DCHECK(second.IsDoubleStackSlot()); |
| 3607 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3608 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3609 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3610 | break; |
| 3611 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3612 | |
| 3613 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3614 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3615 | } |
| 3616 | } |
| 3617 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3618 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3619 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3620 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3621 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3622 | case DataType::Type::kInt32: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3623 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3624 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3625 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3626 | // Can use 3 operand multiply. |
| 3627 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3628 | } else { |
| 3629 | locations->SetOut(Location::SameAsFirstInput()); |
| 3630 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3631 | break; |
| 3632 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3633 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3634 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3635 | locations->SetInAt(1, Location::Any()); |
| 3636 | if (mul->InputAt(1)->IsLongConstant() && |
| 3637 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3638 | // Can use 3 operand multiply. |
| 3639 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3640 | } else { |
| 3641 | locations->SetOut(Location::SameAsFirstInput()); |
| 3642 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3643 | break; |
| 3644 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3645 | case DataType::Type::kFloat32: |
| 3646 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3647 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3648 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3649 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3650 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3651 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3652 | |
| 3653 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3654 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3655 | } |
| 3656 | } |
| 3657 | |
| 3658 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3659 | LocationSummary* locations = mul->GetLocations(); |
| 3660 | Location first = locations->InAt(0); |
| 3661 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3662 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3663 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3664 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3665 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3666 | // problems where the output may not be the same as the first operand. |
| 3667 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3668 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3669 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3670 | } else if (second.IsRegister()) { |
| 3671 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3672 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3673 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3674 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3675 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3676 | __ imull(first.AsRegister<CpuRegister>(), |
| 3677 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3678 | } |
| 3679 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3680 | case DataType::Type::kInt64: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3681 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3682 | // problems where the output may not be the same as the first operand. |
| 3683 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3684 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3685 | if (IsInt<32>(value)) { |
| 3686 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3687 | Immediate(static_cast<int32_t>(value))); |
| 3688 | } else { |
| 3689 | // Have to use the constant area. |
| 3690 | DCHECK(first.Equals(out)); |
| 3691 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3692 | } |
| 3693 | } else if (second.IsRegister()) { |
| 3694 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3695 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3696 | } else { |
| 3697 | DCHECK(second.IsDoubleStackSlot()); |
| 3698 | DCHECK(first.Equals(out)); |
| 3699 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3700 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3701 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3702 | break; |
| 3703 | } |
| 3704 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3705 | case DataType::Type::kFloat32: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3706 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3707 | if (second.IsFpuRegister()) { |
| 3708 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3709 | } else if (second.IsConstant()) { |
| 3710 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3711 | codegen_->LiteralFloatAddress( |
| 3712 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3713 | } else { |
| 3714 | DCHECK(second.IsStackSlot()); |
| 3715 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3716 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3717 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3718 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3719 | } |
| 3720 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3721 | case DataType::Type::kFloat64: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3722 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3723 | if (second.IsFpuRegister()) { |
| 3724 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3725 | } else if (second.IsConstant()) { |
| 3726 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3727 | codegen_->LiteralDoubleAddress( |
| 3728 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3729 | } else { |
| 3730 | DCHECK(second.IsDoubleStackSlot()); |
| 3731 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3732 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3733 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3734 | break; |
| 3735 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3736 | |
| 3737 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3738 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3739 | } |
| 3740 | } |
| 3741 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3742 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3743 | uint32_t stack_adjustment, bool is_float) { |
| 3744 | if (source.IsStackSlot()) { |
| 3745 | DCHECK(is_float); |
| 3746 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3747 | } else if (source.IsDoubleStackSlot()) { |
| 3748 | DCHECK(!is_float); |
| 3749 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3750 | } else { |
| 3751 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3752 | if (is_float) { |
| 3753 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3754 | codegen_->Move(stack_temp, source); |
| 3755 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3756 | } else { |
| 3757 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3758 | codegen_->Move(stack_temp, source); |
| 3759 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3760 | } |
| 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3765 | DataType::Type type = rem->GetResultType(); |
| 3766 | bool is_float = type == DataType::Type::kFloat32; |
| 3767 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3768 | LocationSummary* locations = rem->GetLocations(); |
| 3769 | Location first = locations->InAt(0); |
| 3770 | Location second = locations->InAt(1); |
| 3771 | Location out = locations->Out(); |
| 3772 | |
| 3773 | // Create stack space for 2 elements. |
| 3774 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3775 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3776 | |
| 3777 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3778 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3779 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3780 | |
| 3781 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3782 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3783 | __ Bind(&retry); |
| 3784 | __ fprem(); |
| 3785 | |
| 3786 | // Move FP status to AX. |
| 3787 | __ fstsw(); |
| 3788 | |
| 3789 | // And see if the argument reduction is complete. This is signaled by the |
| 3790 | // C2 FPU flag bit set to 0. |
| 3791 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3792 | __ j(kNotEqual, &retry); |
| 3793 | |
| 3794 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3795 | // Store FP top of stack to real stack. |
| 3796 | if (is_float) { |
| 3797 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3798 | } else { |
| 3799 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3800 | } |
| 3801 | |
| 3802 | // Pop the 2 items from the FP stack. |
| 3803 | __ fucompp(); |
| 3804 | |
| 3805 | // Load the value from the stack into an XMM register. |
| 3806 | DCHECK(out.IsFpuRegister()) << out; |
| 3807 | if (is_float) { |
| 3808 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3809 | } else { |
| 3810 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3811 | } |
| 3812 | |
| 3813 | // And remove the temporary stack space we allocated. |
| 3814 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3815 | } |
| 3816 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3817 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3818 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3819 | |
| 3820 | LocationSummary* locations = instruction->GetLocations(); |
| 3821 | Location second = locations->InAt(1); |
| 3822 | DCHECK(second.IsConstant()); |
| 3823 | |
| 3824 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3825 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3826 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3827 | |
| 3828 | DCHECK(imm == 1 || imm == -1); |
| 3829 | |
| 3830 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3831 | case DataType::Type::kInt32: { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3832 | if (instruction->IsRem()) { |
| 3833 | __ xorl(output_register, output_register); |
| 3834 | } else { |
| 3835 | __ movl(output_register, input_register); |
| 3836 | if (imm == -1) { |
| 3837 | __ negl(output_register); |
| 3838 | } |
| 3839 | } |
| 3840 | break; |
| 3841 | } |
| 3842 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3843 | case DataType::Type::kInt64: { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3844 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3845 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3846 | } else { |
| 3847 | __ movq(output_register, input_register); |
| 3848 | if (imm == -1) { |
| 3849 | __ negq(output_register); |
| 3850 | } |
| 3851 | } |
| 3852 | break; |
| 3853 | } |
| 3854 | |
| 3855 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3856 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3857 | } |
| 3858 | } |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3859 | void InstructionCodeGeneratorX86_64::RemByPowerOfTwo(HRem* instruction) { |
| 3860 | LocationSummary* locations = instruction->GetLocations(); |
| 3861 | Location second = locations->InAt(1); |
| 3862 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3863 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3864 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3865 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3866 | uint64_t abs_imm = AbsOrMin(imm); |
| 3867 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3868 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3869 | NearLabel done; |
| 3870 | __ movl(out, numerator); |
| 3871 | __ andl(out, Immediate(abs_imm-1)); |
| 3872 | __ j(Condition::kZero, &done); |
| 3873 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 3874 | __ testl(numerator, numerator); |
| 3875 | __ cmov(Condition::kLess, out, tmp, false); |
| 3876 | __ Bind(&done); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3877 | |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3878 | } else { |
| 3879 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3880 | codegen_->Load64BitValue(tmp, abs_imm - 1); |
| 3881 | NearLabel done; |
| 3882 | |
| 3883 | __ movq(out, numerator); |
| 3884 | __ andq(out, tmp); |
| 3885 | __ j(Condition::kZero, &done); |
| 3886 | __ movq(tmp, numerator); |
| 3887 | __ sarq(tmp, Immediate(63)); |
| 3888 | __ shlq(tmp, Immediate(WhichPowerOf2(abs_imm))); |
| 3889 | __ orq(out, tmp); |
| 3890 | __ Bind(&done); |
| 3891 | } |
| 3892 | } |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3893 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3894 | LocationSummary* locations = instruction->GetLocations(); |
| 3895 | Location second = locations->InAt(1); |
| 3896 | |
| 3897 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3898 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3899 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3900 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3901 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3902 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3903 | |
| 3904 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3905 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3906 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 3907 | // When denominator is equal to 2, we can add signed bit and numerator to tmp. |
| 3908 | // Below we are using addl instruction instead of cmov which give us 1 cycle benefit. |
| 3909 | if (abs_imm == 2) { |
| 3910 | __ leal(tmp, Address(numerator, 0)); |
| 3911 | __ shrl(tmp, Immediate(31)); |
| 3912 | __ addl(tmp, numerator); |
| 3913 | } else { |
| 3914 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
| 3915 | __ testl(numerator, numerator); |
| 3916 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3917 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3918 | int shift = CTZ(imm); |
| 3919 | __ sarl(tmp, Immediate(shift)); |
| 3920 | |
| 3921 | if (imm < 0) { |
| 3922 | __ negl(tmp); |
| 3923 | } |
| 3924 | |
| 3925 | __ movl(output_register, tmp); |
| 3926 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3927 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3928 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 3929 | if (abs_imm == 2) { |
| 3930 | __ movq(rdx, numerator); |
| 3931 | __ shrq(rdx, Immediate(63)); |
| 3932 | __ addq(rdx, numerator); |
| 3933 | } else { |
| 3934 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
| 3935 | __ addq(rdx, numerator); |
| 3936 | __ testq(numerator, numerator); |
| 3937 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3938 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3939 | int shift = CTZ(imm); |
| 3940 | __ sarq(rdx, Immediate(shift)); |
| 3941 | |
| 3942 | if (imm < 0) { |
| 3943 | __ negq(rdx); |
| 3944 | } |
| 3945 | |
| 3946 | __ movq(output_register, rdx); |
| 3947 | } |
| 3948 | } |
| 3949 | |
| 3950 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3951 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3952 | |
| 3953 | LocationSummary* locations = instruction->GetLocations(); |
| 3954 | Location second = locations->InAt(1); |
| 3955 | |
| 3956 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3957 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3958 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3959 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3960 | : locations->Out().AsRegister<CpuRegister>(); |
| 3961 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3962 | |
| 3963 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3964 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3965 | if (instruction->IsDiv()) { |
| 3966 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3967 | } else { |
| 3968 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3969 | } |
| 3970 | |
| 3971 | int64_t magic; |
| 3972 | int shift; |
| 3973 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3974 | // TODO: can these branches be written as one? |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3975 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3976 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3977 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3978 | CalculateMagicAndShiftForDivRem(imm, false /* is_long= */, &magic, &shift); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3979 | |
| 3980 | __ movl(numerator, eax); |
| 3981 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3982 | __ movl(eax, Immediate(magic)); |
| 3983 | __ imull(numerator); |
| 3984 | |
| 3985 | if (imm > 0 && magic < 0) { |
| 3986 | __ addl(edx, numerator); |
| 3987 | } else if (imm < 0 && magic > 0) { |
| 3988 | __ subl(edx, numerator); |
| 3989 | } |
| 3990 | |
| 3991 | if (shift != 0) { |
| 3992 | __ sarl(edx, Immediate(shift)); |
| 3993 | } |
| 3994 | |
| 3995 | __ movl(eax, edx); |
| 3996 | __ shrl(edx, Immediate(31)); |
| 3997 | __ addl(edx, eax); |
| 3998 | |
| 3999 | if (instruction->IsRem()) { |
| 4000 | __ movl(eax, numerator); |
| 4001 | __ imull(edx, Immediate(imm)); |
| 4002 | __ subl(eax, edx); |
| 4003 | __ movl(edx, eax); |
| 4004 | } else { |
| 4005 | __ movl(eax, edx); |
| 4006 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4007 | } else { |
| 4008 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 4009 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4010 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4011 | |
| 4012 | CpuRegister rax = eax; |
| 4013 | CpuRegister rdx = edx; |
| 4014 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4015 | CalculateMagicAndShiftForDivRem(imm, true /* is_long= */, &magic, &shift); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4016 | |
| 4017 | // Save the numerator. |
| 4018 | __ movq(numerator, rax); |
| 4019 | |
| 4020 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4021 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4022 | |
| 4023 | // RDX:RAX = magic * numerator |
| 4024 | __ imulq(numerator); |
| 4025 | |
| 4026 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4027 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4028 | __ addq(rdx, numerator); |
| 4029 | } else if (imm < 0 && magic > 0) { |
| 4030 | // RDX -= numerator |
| 4031 | __ subq(rdx, numerator); |
| 4032 | } |
| 4033 | |
| 4034 | // Shift if needed. |
| 4035 | if (shift != 0) { |
| 4036 | __ sarq(rdx, Immediate(shift)); |
| 4037 | } |
| 4038 | |
| 4039 | // RDX += 1 if RDX < 0 |
| 4040 | __ movq(rax, rdx); |
| 4041 | __ shrq(rdx, Immediate(63)); |
| 4042 | __ addq(rdx, rax); |
| 4043 | |
| 4044 | if (instruction->IsRem()) { |
| 4045 | __ movq(rax, numerator); |
| 4046 | |
| 4047 | if (IsInt<32>(imm)) { |
| 4048 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 4049 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4050 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | __ subq(rax, rdx); |
| 4054 | __ movq(rdx, rax); |
| 4055 | } else { |
| 4056 | __ movq(rax, rdx); |
| 4057 | } |
| 4058 | } |
| 4059 | } |
| 4060 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4061 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 4062 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4063 | DataType::Type type = instruction->GetResultType(); |
| 4064 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4065 | |
| 4066 | bool is_div = instruction->IsDiv(); |
| 4067 | LocationSummary* locations = instruction->GetLocations(); |
| 4068 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4069 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4070 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4071 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4072 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4073 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4074 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4075 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 4076 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4077 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4078 | if (imm == 0) { |
| 4079 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4080 | } else if (imm == 1 || imm == -1) { |
| 4081 | DivRemOneOrMinusOne(instruction); |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 4082 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4083 | if (is_div) { |
| 4084 | DivByPowerOfTwo(instruction->AsDiv()); |
| 4085 | } else { |
| 4086 | RemByPowerOfTwo(instruction->AsRem()); |
| 4087 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4088 | } else { |
| 4089 | DCHECK(imm <= -2 || imm >= 2); |
| 4090 | GenerateDivRemWithAnyConstant(instruction); |
| 4091 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4092 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4093 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4094 | new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 4095 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4096 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4097 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4098 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4099 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 4100 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 4101 | // 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] | 4102 | if (type == DataType::Type::kInt32) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4103 | __ cmpl(second_reg, Immediate(-1)); |
| 4104 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4105 | // edx:eax <- sign-extended of eax |
| 4106 | __ cdq(); |
| 4107 | // eax = quotient, edx = remainder |
| 4108 | __ idivl(second_reg); |
| 4109 | } else { |
| 4110 | __ cmpq(second_reg, Immediate(-1)); |
| 4111 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4112 | // rdx:rax <- sign-extended of rax |
| 4113 | __ cqo(); |
| 4114 | // rax = quotient, rdx = remainder |
| 4115 | __ idivq(second_reg); |
| 4116 | } |
| 4117 | __ Bind(slow_path->GetExitLabel()); |
| 4118 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4119 | } |
| 4120 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4121 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 4122 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4123 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4124 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4125 | case DataType::Type::kInt32: |
| 4126 | case DataType::Type::kInt64: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4127 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4128 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4129 | locations->SetOut(Location::SameAsFirstInput()); |
| 4130 | // Intel uses edx:eax as the dividend. |
| 4131 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4132 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 4133 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 4134 | // output and request another temp. |
| 4135 | if (div->InputAt(1)->IsConstant()) { |
| 4136 | locations->AddTemp(Location::RequiresRegister()); |
| 4137 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4138 | break; |
| 4139 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4140 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4141 | case DataType::Type::kFloat32: |
| 4142 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4143 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4144 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4145 | locations->SetOut(Location::SameAsFirstInput()); |
| 4146 | break; |
| 4147 | } |
| 4148 | |
| 4149 | default: |
| 4150 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 4155 | LocationSummary* locations = div->GetLocations(); |
| 4156 | Location first = locations->InAt(0); |
| 4157 | Location second = locations->InAt(1); |
| 4158 | DCHECK(first.Equals(locations->Out())); |
| 4159 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4160 | DataType::Type type = div->GetResultType(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4161 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4162 | case DataType::Type::kInt32: |
| 4163 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4164 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4165 | break; |
| 4166 | } |
| 4167 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4168 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4169 | if (second.IsFpuRegister()) { |
| 4170 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 4171 | } else if (second.IsConstant()) { |
| 4172 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4173 | codegen_->LiteralFloatAddress( |
| 4174 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4175 | } else { |
| 4176 | DCHECK(second.IsStackSlot()); |
| 4177 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 4178 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 4179 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4180 | break; |
| 4181 | } |
| 4182 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4183 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4184 | if (second.IsFpuRegister()) { |
| 4185 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 4186 | } else if (second.IsConstant()) { |
| 4187 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4188 | codegen_->LiteralDoubleAddress( |
| 4189 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4190 | } else { |
| 4191 | DCHECK(second.IsDoubleStackSlot()); |
| 4192 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 4193 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 4194 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4195 | break; |
| 4196 | } |
| 4197 | |
| 4198 | default: |
| 4199 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4200 | } |
| 4201 | } |
| 4202 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4203 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4204 | DataType::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4205 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4206 | new (GetGraph()->GetAllocator()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4207 | |
| 4208 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4209 | case DataType::Type::kInt32: |
| 4210 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4211 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4212 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4213 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 4214 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 4215 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 4216 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 4217 | // output and request another temp. |
| 4218 | if (rem->InputAt(1)->IsConstant()) { |
| 4219 | locations->AddTemp(Location::RequiresRegister()); |
| 4220 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4221 | break; |
| 4222 | } |
| 4223 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4224 | case DataType::Type::kFloat32: |
| 4225 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4226 | locations->SetInAt(0, Location::Any()); |
| 4227 | locations->SetInAt(1, Location::Any()); |
| 4228 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4229 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4230 | break; |
| 4231 | } |
| 4232 | |
| 4233 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4234 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4235 | } |
| 4236 | } |
| 4237 | |
| 4238 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4239 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4240 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4241 | case DataType::Type::kInt32: |
| 4242 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4243 | GenerateDivRemIntegral(rem); |
| 4244 | break; |
| 4245 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4246 | case DataType::Type::kFloat32: |
| 4247 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 4248 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4249 | break; |
| 4250 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4251 | default: |
| 4252 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 4253 | } |
| 4254 | } |
| 4255 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4256 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4257 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4258 | switch (minmax->GetResultType()) { |
| 4259 | case DataType::Type::kInt32: |
| 4260 | case DataType::Type::kInt64: |
| 4261 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4262 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4263 | locations->SetOut(Location::SameAsFirstInput()); |
| 4264 | break; |
| 4265 | case DataType::Type::kFloat32: |
| 4266 | case DataType::Type::kFloat64: |
| 4267 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4268 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4269 | // The following is sub-optimal, but all we can do for now. It would be fine to also accept |
| 4270 | // the second input to be the output (we can simply swap inputs). |
| 4271 | locations->SetOut(Location::SameAsFirstInput()); |
| 4272 | break; |
| 4273 | default: |
| 4274 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4275 | } |
| 4276 | } |
| 4277 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4278 | void InstructionCodeGeneratorX86_64::GenerateMinMaxInt(LocationSummary* locations, |
| 4279 | bool is_min, |
| 4280 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4281 | Location op1_loc = locations->InAt(0); |
| 4282 | Location op2_loc = locations->InAt(1); |
| 4283 | |
| 4284 | // Shortcut for same input locations. |
| 4285 | if (op1_loc.Equals(op2_loc)) { |
| 4286 | // Can return immediately, as op1_loc == out_loc. |
| 4287 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 4288 | // a copy here. |
| 4289 | DCHECK(locations->Out().Equals(op1_loc)); |
| 4290 | return; |
| 4291 | } |
| 4292 | |
| 4293 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4294 | CpuRegister op2 = op2_loc.AsRegister<CpuRegister>(); |
| 4295 | |
| 4296 | // (out := op1) |
| 4297 | // out <=? op2 |
| 4298 | // if out is min jmp done |
| 4299 | // out := op2 |
| 4300 | // done: |
| 4301 | |
| 4302 | if (type == DataType::Type::kInt64) { |
| 4303 | __ cmpq(out, op2); |
| 4304 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ true); |
| 4305 | } else { |
| 4306 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 4307 | __ cmpl(out, op2); |
| 4308 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ false); |
| 4309 | } |
| 4310 | } |
| 4311 | |
| 4312 | void InstructionCodeGeneratorX86_64::GenerateMinMaxFP(LocationSummary* locations, |
| 4313 | bool is_min, |
| 4314 | DataType::Type type) { |
| 4315 | Location op1_loc = locations->InAt(0); |
| 4316 | Location op2_loc = locations->InAt(1); |
| 4317 | Location out_loc = locations->Out(); |
| 4318 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4319 | |
| 4320 | // Shortcut for same input locations. |
| 4321 | if (op1_loc.Equals(op2_loc)) { |
| 4322 | DCHECK(out_loc.Equals(op1_loc)); |
| 4323 | return; |
| 4324 | } |
| 4325 | |
| 4326 | // (out := op1) |
| 4327 | // out <=? op2 |
| 4328 | // if Nan jmp Nan_label |
| 4329 | // if out is min jmp done |
| 4330 | // if op2 is min jmp op2_label |
| 4331 | // handle -0/+0 |
| 4332 | // jmp done |
| 4333 | // Nan_label: |
| 4334 | // out := NaN |
| 4335 | // op2_label: |
| 4336 | // out := op2 |
| 4337 | // done: |
| 4338 | // |
| 4339 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4340 | // |
| 4341 | // TODO: This is straight from Quick. Make NaN an out-of-line slowpath? |
| 4342 | |
| 4343 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4344 | |
| 4345 | NearLabel nan, done, op2_label; |
| 4346 | if (type == DataType::Type::kFloat64) { |
| 4347 | __ ucomisd(out, op2); |
| 4348 | } else { |
| 4349 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4350 | __ ucomiss(out, op2); |
| 4351 | } |
| 4352 | |
| 4353 | __ j(Condition::kParityEven, &nan); |
| 4354 | |
| 4355 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4356 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4357 | |
| 4358 | // Handle 0.0/-0.0. |
| 4359 | if (is_min) { |
| 4360 | if (type == DataType::Type::kFloat64) { |
| 4361 | __ orpd(out, op2); |
| 4362 | } else { |
| 4363 | __ orps(out, op2); |
| 4364 | } |
| 4365 | } else { |
| 4366 | if (type == DataType::Type::kFloat64) { |
| 4367 | __ andpd(out, op2); |
| 4368 | } else { |
| 4369 | __ andps(out, op2); |
| 4370 | } |
| 4371 | } |
| 4372 | __ jmp(&done); |
| 4373 | |
| 4374 | // NaN handling. |
| 4375 | __ Bind(&nan); |
| 4376 | if (type == DataType::Type::kFloat64) { |
| 4377 | __ movsd(out, codegen_->LiteralInt64Address(INT64_C(0x7FF8000000000000))); |
| 4378 | } else { |
| 4379 | __ movss(out, codegen_->LiteralInt32Address(INT32_C(0x7FC00000))); |
| 4380 | } |
| 4381 | __ jmp(&done); |
| 4382 | |
| 4383 | // out := op2; |
| 4384 | __ Bind(&op2_label); |
| 4385 | if (type == DataType::Type::kFloat64) { |
| 4386 | __ movsd(out, op2); |
| 4387 | } else { |
| 4388 | __ movss(out, op2); |
| 4389 | } |
| 4390 | |
| 4391 | // Done. |
| 4392 | __ Bind(&done); |
| 4393 | } |
| 4394 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4395 | void InstructionCodeGeneratorX86_64::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4396 | DataType::Type type = minmax->GetResultType(); |
| 4397 | switch (type) { |
| 4398 | case DataType::Type::kInt32: |
| 4399 | case DataType::Type::kInt64: |
| 4400 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4401 | break; |
| 4402 | case DataType::Type::kFloat32: |
| 4403 | case DataType::Type::kFloat64: |
| 4404 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4405 | break; |
| 4406 | default: |
| 4407 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4408 | } |
| 4409 | } |
| 4410 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4411 | void LocationsBuilderX86_64::VisitMin(HMin* min) { |
| 4412 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4413 | } |
| 4414 | |
| 4415 | void InstructionCodeGeneratorX86_64::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4416 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4417 | } |
| 4418 | |
| 4419 | void LocationsBuilderX86_64::VisitMax(HMax* max) { |
| 4420 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4421 | } |
| 4422 | |
| 4423 | void InstructionCodeGeneratorX86_64::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4424 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4425 | } |
| 4426 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4427 | void LocationsBuilderX86_64::VisitAbs(HAbs* abs) { |
| 4428 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4429 | switch (abs->GetResultType()) { |
| 4430 | case DataType::Type::kInt32: |
| 4431 | case DataType::Type::kInt64: |
| 4432 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4433 | locations->SetOut(Location::SameAsFirstInput()); |
| 4434 | locations->AddTemp(Location::RequiresRegister()); |
| 4435 | break; |
| 4436 | case DataType::Type::kFloat32: |
| 4437 | case DataType::Type::kFloat64: |
| 4438 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4439 | locations->SetOut(Location::SameAsFirstInput()); |
| 4440 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4441 | break; |
| 4442 | default: |
| 4443 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4444 | } |
| 4445 | } |
| 4446 | |
| 4447 | void InstructionCodeGeneratorX86_64::VisitAbs(HAbs* abs) { |
| 4448 | LocationSummary* locations = abs->GetLocations(); |
| 4449 | switch (abs->GetResultType()) { |
| 4450 | case DataType::Type::kInt32: { |
| 4451 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4452 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4453 | // Create mask. |
| 4454 | __ movl(mask, out); |
| 4455 | __ sarl(mask, Immediate(31)); |
| 4456 | // Add mask. |
| 4457 | __ addl(out, mask); |
| 4458 | __ xorl(out, mask); |
| 4459 | break; |
| 4460 | } |
| 4461 | case DataType::Type::kInt64: { |
| 4462 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4463 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4464 | // Create mask. |
| 4465 | __ movq(mask, out); |
| 4466 | __ sarq(mask, Immediate(63)); |
| 4467 | // Add mask. |
| 4468 | __ addq(out, mask); |
| 4469 | __ xorq(out, mask); |
| 4470 | break; |
| 4471 | } |
| 4472 | case DataType::Type::kFloat32: { |
| 4473 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4474 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4475 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x7FFFFFFF))); |
| 4476 | __ andps(out, mask); |
| 4477 | break; |
| 4478 | } |
| 4479 | case DataType::Type::kFloat64: { |
| 4480 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4481 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4482 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x7FFFFFFFFFFFFFFF))); |
| 4483 | __ andpd(out, mask); |
| 4484 | break; |
| 4485 | } |
| 4486 | default: |
| 4487 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4488 | } |
| 4489 | } |
| 4490 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4491 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4492 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4493 | locations->SetInAt(0, Location::Any()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4494 | } |
| 4495 | |
| 4496 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4497 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4498 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86_64(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4499 | codegen_->AddSlowPath(slow_path); |
| 4500 | |
| 4501 | LocationSummary* locations = instruction->GetLocations(); |
| 4502 | Location value = locations->InAt(0); |
| 4503 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4504 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4505 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4506 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4507 | case DataType::Type::kInt8: |
| 4508 | case DataType::Type::kUint16: |
| 4509 | case DataType::Type::kInt16: |
| 4510 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4511 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4512 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4513 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4514 | } else if (value.IsStackSlot()) { |
| 4515 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4516 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4517 | } else { |
| 4518 | DCHECK(value.IsConstant()) << value; |
| 4519 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4520 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4521 | } |
| 4522 | } |
| 4523 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4524 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4525 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4526 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4527 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4528 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4529 | } else if (value.IsDoubleStackSlot()) { |
| 4530 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4531 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4532 | } else { |
| 4533 | DCHECK(value.IsConstant()) << value; |
| 4534 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4535 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4536 | } |
| 4537 | } |
| 4538 | break; |
| 4539 | } |
| 4540 | default: |
| 4541 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4542 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4543 | } |
| 4544 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4545 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 4546 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4547 | |
| 4548 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4549 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4550 | |
| 4551 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4552 | case DataType::Type::kInt32: |
| 4553 | case DataType::Type::kInt64: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4554 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4555 | // The shift count needs to be in CL. |
| 4556 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 4557 | locations->SetOut(Location::SameAsFirstInput()); |
| 4558 | break; |
| 4559 | } |
| 4560 | default: |
| 4561 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4562 | } |
| 4563 | } |
| 4564 | |
| 4565 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 4566 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4567 | |
| 4568 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4569 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4570 | Location second = locations->InAt(1); |
| 4571 | |
| 4572 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4573 | case DataType::Type::kInt32: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4574 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4575 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4576 | if (op->IsShl()) { |
| 4577 | __ shll(first_reg, second_reg); |
| 4578 | } else if (op->IsShr()) { |
| 4579 | __ sarl(first_reg, second_reg); |
| 4580 | } else { |
| 4581 | __ shrl(first_reg, second_reg); |
| 4582 | } |
| 4583 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4584 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4585 | if (op->IsShl()) { |
| 4586 | __ shll(first_reg, imm); |
| 4587 | } else if (op->IsShr()) { |
| 4588 | __ sarl(first_reg, imm); |
| 4589 | } else { |
| 4590 | __ shrl(first_reg, imm); |
| 4591 | } |
| 4592 | } |
| 4593 | break; |
| 4594 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4595 | case DataType::Type::kInt64: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4596 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4597 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4598 | if (op->IsShl()) { |
| 4599 | __ shlq(first_reg, second_reg); |
| 4600 | } else if (op->IsShr()) { |
| 4601 | __ sarq(first_reg, second_reg); |
| 4602 | } else { |
| 4603 | __ shrq(first_reg, second_reg); |
| 4604 | } |
| 4605 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4606 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4607 | if (op->IsShl()) { |
| 4608 | __ shlq(first_reg, imm); |
| 4609 | } else if (op->IsShr()) { |
| 4610 | __ sarq(first_reg, imm); |
| 4611 | } else { |
| 4612 | __ shrq(first_reg, imm); |
| 4613 | } |
| 4614 | } |
| 4615 | break; |
| 4616 | } |
| 4617 | default: |
| 4618 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4619 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4620 | } |
| 4621 | } |
| 4622 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4623 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 4624 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4625 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4626 | |
| 4627 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4628 | case DataType::Type::kInt32: |
| 4629 | case DataType::Type::kInt64: { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4630 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4631 | // The shift count needs to be in CL (unless it is a constant). |
| 4632 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 4633 | locations->SetOut(Location::SameAsFirstInput()); |
| 4634 | break; |
| 4635 | } |
| 4636 | default: |
| 4637 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4638 | UNREACHABLE(); |
| 4639 | } |
| 4640 | } |
| 4641 | |
| 4642 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4643 | LocationSummary* locations = ror->GetLocations(); |
| 4644 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4645 | Location second = locations->InAt(1); |
| 4646 | |
| 4647 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4648 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4649 | if (second.IsRegister()) { |
| 4650 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4651 | __ rorl(first_reg, second_reg); |
| 4652 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4653 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4654 | __ rorl(first_reg, imm); |
| 4655 | } |
| 4656 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4657 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4658 | if (second.IsRegister()) { |
| 4659 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4660 | __ rorq(first_reg, second_reg); |
| 4661 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4662 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4663 | __ rorq(first_reg, imm); |
| 4664 | } |
| 4665 | break; |
| 4666 | default: |
| 4667 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4668 | UNREACHABLE(); |
| 4669 | } |
| 4670 | } |
| 4671 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4672 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4673 | HandleShift(shl); |
| 4674 | } |
| 4675 | |
| 4676 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4677 | HandleShift(shl); |
| 4678 | } |
| 4679 | |
| 4680 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4681 | HandleShift(shr); |
| 4682 | } |
| 4683 | |
| 4684 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4685 | HandleShift(shr); |
| 4686 | } |
| 4687 | |
| 4688 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4689 | HandleShift(ushr); |
| 4690 | } |
| 4691 | |
| 4692 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4693 | HandleShift(ushr); |
| 4694 | } |
| 4695 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4696 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4697 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4698 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4699 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4700 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4701 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4702 | } |
| 4703 | |
| 4704 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4705 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4706 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4707 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4708 | } |
| 4709 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4710 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4711 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4712 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4713 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4714 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4715 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4716 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4717 | } |
| 4718 | |
| 4719 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4720 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 4721 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4722 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4723 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4724 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4725 | } |
| 4726 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4727 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4728 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4729 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4730 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4731 | if (location.IsStackSlot()) { |
| 4732 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4733 | } else if (location.IsDoubleStackSlot()) { |
| 4734 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4735 | } |
| 4736 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4737 | } |
| 4738 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4739 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4740 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4741 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4742 | } |
| 4743 | |
| 4744 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4745 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4746 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4747 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4748 | } |
| 4749 | |
| 4750 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4751 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4752 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4753 | } |
| 4754 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4755 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4756 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4757 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4758 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4759 | locations->SetOut(Location::RequiresRegister()); |
| 4760 | } |
| 4761 | |
| 4762 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4763 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4764 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4765 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4766 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4767 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4768 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4769 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4770 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4771 | instruction->GetIndex(), kX86_64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4772 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4773 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4774 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4775 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4776 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4777 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4778 | } |
| 4779 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4780 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4781 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4782 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4783 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4784 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4785 | } |
| 4786 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4787 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4788 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4789 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4790 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4791 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4792 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4793 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4794 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4795 | break; |
| 4796 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4797 | case DataType::Type::kInt64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4798 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4799 | break; |
| 4800 | |
| 4801 | default: |
| 4802 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4803 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4804 | } |
| 4805 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4806 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4807 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4808 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4809 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4810 | locations->SetOut(Location::SameAsFirstInput()); |
| 4811 | } |
| 4812 | |
| 4813 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4814 | LocationSummary* locations = bool_not->GetLocations(); |
| 4815 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4816 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4817 | Location out = locations->Out(); |
| 4818 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4819 | } |
| 4820 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4821 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4822 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4823 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4824 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4825 | locations->SetInAt(i, Location::Any()); |
| 4826 | } |
| 4827 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4828 | } |
| 4829 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4830 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4831 | LOG(FATAL) << "Unimplemented"; |
| 4832 | } |
| 4833 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4834 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4835 | /* |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4836 | * 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] | 4837 | * 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] | 4838 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4839 | */ |
| 4840 | switch (kind) { |
| 4841 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4842 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4843 | break; |
| 4844 | } |
| 4845 | case MemBarrierKind::kAnyStore: |
| 4846 | case MemBarrierKind::kLoadAny: |
| 4847 | case MemBarrierKind::kStoreStore: { |
| 4848 | // nop |
| 4849 | break; |
| 4850 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4851 | case MemBarrierKind::kNTStoreStore: |
| 4852 | // Non-Temporal Store/Store needs an explicit fence. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4853 | MemoryFence(/* non-temporal= */ true); |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4854 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4855 | } |
| 4856 | } |
| 4857 | |
| 4858 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4859 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4860 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4861 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4862 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4863 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4864 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4865 | object_field_get_with_read_barrier |
| 4866 | ? LocationSummary::kCallOnSlowPath |
| 4867 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4868 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4869 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4870 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4871 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4872 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4873 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4874 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4875 | // The output overlaps for an object field get when read barriers |
| 4876 | // are enabled: we do not want the move to overwrite the object's |
| 4877 | // location, as we need it to emit the read barrier. |
| 4878 | locations->SetOut( |
| 4879 | Location::RequiresRegister(), |
| 4880 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4881 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4885 | const FieldInfo& field_info) { |
| 4886 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4887 | |
| 4888 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4889 | Location base_loc = locations->InAt(0); |
| 4890 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4891 | Location out = locations->Out(); |
| 4892 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4893 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4894 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4895 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4896 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4897 | switch (load_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4898 | case DataType::Type::kBool: |
| 4899 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4900 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4901 | break; |
| 4902 | } |
| 4903 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4904 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4905 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4906 | break; |
| 4907 | } |
| 4908 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4909 | case DataType::Type::kUint16: { |
| 4910 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4911 | break; |
| 4912 | } |
| 4913 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4914 | case DataType::Type::kInt16: { |
| 4915 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4916 | break; |
| 4917 | } |
| 4918 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4919 | case DataType::Type::kInt32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4920 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4921 | break; |
| 4922 | } |
| 4923 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4924 | case DataType::Type::kReference: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4925 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4926 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4927 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4928 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4929 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4930 | instruction, out, base, offset, /* needs_null_check= */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4931 | if (is_volatile) { |
| 4932 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4933 | } |
| 4934 | } else { |
| 4935 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4936 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4937 | if (is_volatile) { |
| 4938 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4939 | } |
| 4940 | // If read barriers are enabled, emit read barriers other than |
| 4941 | // Baker's using a slow path (and also unpoison the loaded |
| 4942 | // reference, if heap poisoning is enabled). |
| 4943 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4944 | } |
| 4945 | break; |
| 4946 | } |
| 4947 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4948 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4949 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4950 | break; |
| 4951 | } |
| 4952 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4953 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4954 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4955 | break; |
| 4956 | } |
| 4957 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4958 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4959 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4960 | break; |
| 4961 | } |
| 4962 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4963 | case DataType::Type::kUint32: |
| 4964 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4965 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4966 | LOG(FATAL) << "Unreachable type " << load_type; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4967 | UNREACHABLE(); |
| 4968 | } |
| 4969 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4970 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4971 | // Potential implicit null checks, in the case of reference |
| 4972 | // fields, are handled in the previous switch statement. |
| 4973 | } else { |
| 4974 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4975 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4976 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4977 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4978 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4979 | // Memory barriers, in the case of references, are also handled |
| 4980 | // in the previous switch statement. |
| 4981 | } else { |
| 4982 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4983 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4984 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4985 | } |
| 4986 | |
| 4987 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4988 | const FieldInfo& field_info) { |
| 4989 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4990 | |
| 4991 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4992 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4993 | DataType::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4994 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4995 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4996 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4997 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4998 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4999 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5000 | if (is_volatile) { |
| 5001 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 5002 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 5003 | } else { |
| 5004 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 5005 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5006 | } else { |
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::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 5010 | } else { |
| 5011 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5012 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5013 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5014 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 5015 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5016 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5017 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5018 | } else if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5019 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 5020 | locations->AddTemp(Location::RequiresRegister()); |
| 5021 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5022 | } |
| 5023 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5024 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5025 | const FieldInfo& field_info, |
| 5026 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5027 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5028 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5029 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5030 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5031 | Location value = locations->InAt(1); |
| 5032 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5033 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5034 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5035 | |
| 5036 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5037 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5038 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5039 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5040 | bool maybe_record_implicit_null_check_done = false; |
| 5041 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5042 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5043 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5044 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5045 | case DataType::Type::kInt8: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5046 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5047 | __ movb(Address(base, offset), |
| 5048 | Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5049 | } else { |
| 5050 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 5051 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5052 | break; |
| 5053 | } |
| 5054 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5055 | case DataType::Type::kUint16: |
| 5056 | case DataType::Type::kInt16: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5057 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5058 | __ movw(Address(base, offset), |
| 5059 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5060 | } else { |
| 5061 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 5062 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5063 | break; |
| 5064 | } |
| 5065 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5066 | case DataType::Type::kInt32: |
| 5067 | case DataType::Type::kReference: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5068 | if (value.IsConstant()) { |
| 5069 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5070 | // `field_type == DataType::Type::kReference` implies `v == 0`. |
| 5071 | DCHECK((field_type != DataType::Type::kReference) || (v == 0)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5072 | // Note: if heap poisoning is enabled, no need to poison |
| 5073 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 5074 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5075 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5076 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5077 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 5078 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 5079 | __ PoisonHeapReference(temp); |
| 5080 | __ movl(Address(base, offset), temp); |
| 5081 | } else { |
| 5082 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 5083 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5084 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5085 | break; |
| 5086 | } |
| 5087 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5088 | case DataType::Type::kInt64: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5089 | if (value.IsConstant()) { |
| 5090 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5091 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 5092 | Address(base, offset + sizeof(int32_t)), |
| 5093 | v, |
| 5094 | instruction); |
| 5095 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5096 | } else { |
| 5097 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 5098 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5099 | break; |
| 5100 | } |
| 5101 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5102 | case DataType::Type::kFloat32: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5103 | if (value.IsConstant()) { |
| 5104 | int32_t v = |
| 5105 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5106 | __ movl(Address(base, offset), Immediate(v)); |
| 5107 | } else { |
| 5108 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5109 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5110 | break; |
| 5111 | } |
| 5112 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5113 | case DataType::Type::kFloat64: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5114 | if (value.IsConstant()) { |
| 5115 | int64_t v = |
| 5116 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5117 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 5118 | Address(base, offset + sizeof(int32_t)), |
| 5119 | v, |
| 5120 | instruction); |
| 5121 | maybe_record_implicit_null_check_done = true; |
| 5122 | } else { |
| 5123 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 5124 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5125 | break; |
| 5126 | } |
| 5127 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5128 | case DataType::Type::kUint32: |
| 5129 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5130 | case DataType::Type::kVoid: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5131 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5132 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5133 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5134 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5135 | if (!maybe_record_implicit_null_check_done) { |
| 5136 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5137 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5138 | |
| 5139 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5140 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 5141 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5142 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5143 | } |
| 5144 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5145 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5146 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5147 | } |
| 5148 | } |
| 5149 | |
| 5150 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5151 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5152 | } |
| 5153 | |
| 5154 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5155 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5156 | } |
| 5157 | |
| 5158 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5159 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5160 | } |
| 5161 | |
| 5162 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5163 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5164 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5165 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5166 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5167 | HandleFieldGet(instruction); |
| 5168 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5169 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5170 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5171 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5172 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5173 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5174 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5175 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5176 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5177 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5178 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5179 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5180 | } |
| 5181 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 5182 | void LocationsBuilderX86_64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5183 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(RAX)); |
| 5184 | } |
| 5185 | |
| 5186 | void InstructionCodeGeneratorX86_64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5187 | __ movl(CpuRegister(RDI), Immediate(instruction->GetFormat()->GetValue())); |
| 5188 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 5189 | } |
| 5190 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5191 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 5192 | HUnresolvedInstanceFieldGet* instruction) { |
| 5193 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5194 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5195 | instruction, instruction->GetFieldType(), calling_convention); |
| 5196 | } |
| 5197 | |
| 5198 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 5199 | HUnresolvedInstanceFieldGet* instruction) { |
| 5200 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5201 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5202 | instruction->GetFieldType(), |
| 5203 | instruction->GetFieldIndex(), |
| 5204 | instruction->GetDexPc(), |
| 5205 | calling_convention); |
| 5206 | } |
| 5207 | |
| 5208 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 5209 | HUnresolvedInstanceFieldSet* instruction) { |
| 5210 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5211 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5212 | instruction, instruction->GetFieldType(), calling_convention); |
| 5213 | } |
| 5214 | |
| 5215 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 5216 | HUnresolvedInstanceFieldSet* instruction) { |
| 5217 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5218 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5219 | instruction->GetFieldType(), |
| 5220 | instruction->GetFieldIndex(), |
| 5221 | instruction->GetDexPc(), |
| 5222 | calling_convention); |
| 5223 | } |
| 5224 | |
| 5225 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 5226 | HUnresolvedStaticFieldGet* instruction) { |
| 5227 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5228 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5229 | instruction, instruction->GetFieldType(), calling_convention); |
| 5230 | } |
| 5231 | |
| 5232 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 5233 | HUnresolvedStaticFieldGet* instruction) { |
| 5234 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5235 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5236 | instruction->GetFieldType(), |
| 5237 | instruction->GetFieldIndex(), |
| 5238 | instruction->GetDexPc(), |
| 5239 | calling_convention); |
| 5240 | } |
| 5241 | |
| 5242 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 5243 | HUnresolvedStaticFieldSet* instruction) { |
| 5244 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5245 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5246 | instruction, instruction->GetFieldType(), calling_convention); |
| 5247 | } |
| 5248 | |
| 5249 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 5250 | HUnresolvedStaticFieldSet* instruction) { |
| 5251 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5252 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5253 | instruction->GetFieldType(), |
| 5254 | instruction->GetFieldIndex(), |
| 5255 | instruction->GetDexPc(), |
| 5256 | calling_convention); |
| 5257 | } |
| 5258 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5259 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5260 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5261 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5262 | ? Location::RequiresRegister() |
| 5263 | : Location::Any(); |
| 5264 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5265 | } |
| 5266 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5267 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5268 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5269 | return; |
| 5270 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5271 | LocationSummary* locations = instruction->GetLocations(); |
| 5272 | Location obj = locations->InAt(0); |
| 5273 | |
| 5274 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5275 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5276 | } |
| 5277 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5278 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5279 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5280 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5281 | |
| 5282 | LocationSummary* locations = instruction->GetLocations(); |
| 5283 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5284 | |
| 5285 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5286 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5287 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5288 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5289 | } else { |
| 5290 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5291 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5292 | __ jmp(slow_path->GetEntryLabel()); |
| 5293 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5294 | } |
| 5295 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5296 | } |
| 5297 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5298 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5299 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5300 | } |
| 5301 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5302 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5303 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5304 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5305 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5306 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5307 | object_array_get_with_read_barrier |
| 5308 | ? LocationSummary::kCallOnSlowPath |
| 5309 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5310 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5311 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5312 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5313 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5314 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5315 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5316 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5317 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5318 | // The output overlaps for an object array get when read barriers |
| 5319 | // are enabled: we do not want the move to overwrite the array's |
| 5320 | // location, as we need it to emit the read barrier. |
| 5321 | locations->SetOut( |
| 5322 | Location::RequiresRegister(), |
| 5323 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5324 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 5328 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5329 | Location obj_loc = locations->InAt(0); |
| 5330 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5331 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5332 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5333 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5334 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5335 | DataType::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5336 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5337 | case DataType::Type::kBool: |
| 5338 | case DataType::Type::kUint8: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5339 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5340 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5341 | break; |
| 5342 | } |
| 5343 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5344 | case DataType::Type::kInt8: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5345 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5346 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5347 | break; |
| 5348 | } |
| 5349 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5350 | case DataType::Type::kUint16: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5351 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5352 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5353 | // Branch cases into compressed and uncompressed for each index's type. |
| 5354 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5355 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5356 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5357 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5358 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5359 | "Expecting 0=compressed, 1=uncompressed"); |
| 5360 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5361 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5362 | __ jmp(&done); |
| 5363 | __ Bind(¬_compressed); |
| 5364 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5365 | __ Bind(&done); |
| 5366 | } else { |
| 5367 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5368 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5369 | break; |
| 5370 | } |
| 5371 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5372 | case DataType::Type::kInt16: { |
| 5373 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 5374 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5375 | break; |
| 5376 | } |
| 5377 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5378 | case DataType::Type::kInt32: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5379 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5380 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5381 | break; |
| 5382 | } |
| 5383 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5384 | case DataType::Type::kReference: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5385 | static_assert( |
| 5386 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5387 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5388 | // /* HeapReference<Object> */ out = |
| 5389 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5390 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5391 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5392 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5393 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5394 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5395 | } else { |
| 5396 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5397 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5398 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5399 | // If read barriers are enabled, emit read barriers other than |
| 5400 | // Baker's using a slow path (and also unpoison the loaded |
| 5401 | // reference, if heap poisoning is enabled). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5402 | if (index.IsConstant()) { |
| 5403 | uint32_t offset = |
| 5404 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5405 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5406 | } else { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5407 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5408 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5409 | } |
| 5410 | } |
| 5411 | break; |
| 5412 | } |
| 5413 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5414 | case DataType::Type::kInt64: { |
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 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5417 | break; |
| 5418 | } |
| 5419 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5420 | case DataType::Type::kFloat32: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5421 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5422 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5423 | break; |
| 5424 | } |
| 5425 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5426 | case DataType::Type::kFloat64: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5427 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5428 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5429 | break; |
| 5430 | } |
| 5431 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5432 | case DataType::Type::kUint32: |
| 5433 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5434 | case DataType::Type::kVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5435 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5436 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5437 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5438 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5439 | if (type == DataType::Type::kReference) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5440 | // Potential implicit null checks, in the case of reference |
| 5441 | // arrays, are handled in the previous switch statement. |
| 5442 | } else { |
| 5443 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5444 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5445 | } |
| 5446 | |
| 5447 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5448 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5449 | |
| 5450 | bool needs_write_barrier = |
| 5451 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5452 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5453 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5454 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5455 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5456 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5457 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5458 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5459 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5460 | if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5461 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5462 | } else { |
| 5463 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5464 | } |
| 5465 | |
| 5466 | if (needs_write_barrier) { |
| 5467 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5468 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5469 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5470 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5471 | } |
| 5472 | |
| 5473 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 5474 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5475 | Location array_loc = locations->InAt(0); |
| 5476 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5477 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5478 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5479 | DataType::Type value_type = instruction->GetComponentType(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5480 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5481 | bool needs_write_barrier = |
| 5482 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5483 | |
| 5484 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5485 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5486 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5487 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5488 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5489 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5490 | if (value.IsRegister()) { |
| 5491 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5492 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5493 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5494 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5495 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5496 | break; |
| 5497 | } |
| 5498 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5499 | case DataType::Type::kUint16: |
| 5500 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5501 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5502 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5503 | if (value.IsRegister()) { |
| 5504 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5505 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5506 | DCHECK(value.IsConstant()) << value; |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5507 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5508 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5509 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5510 | break; |
| 5511 | } |
| 5512 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5513 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5514 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5515 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5516 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5517 | if (!value.IsRegister()) { |
| 5518 | // Just setting null. |
| 5519 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5520 | DCHECK(value.IsConstant()) << value; |
| 5521 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5522 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5523 | DCHECK(!needs_write_barrier); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5524 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5525 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5526 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5527 | |
| 5528 | DCHECK(needs_write_barrier); |
| 5529 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5530 | Location temp_loc = locations->GetTemp(0); |
| 5531 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5532 | |
| 5533 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 5534 | NearLabel do_store; |
| 5535 | if (can_value_be_null) { |
| 5536 | __ testl(register_value, register_value); |
| 5537 | __ j(kEqual, &do_store); |
| 5538 | } |
| 5539 | |
| 5540 | SlowPathCode* slow_path = nullptr; |
| 5541 | if (needs_type_check) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5542 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86_64(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5543 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5544 | |
| 5545 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5546 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5547 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5548 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5549 | // Note that when Baker read barriers are enabled, the type |
| 5550 | // checks are performed without read barriers. This is fine, |
| 5551 | // even in the case where a class object is in the from-space |
| 5552 | // after the flip, as a comparison involving such a type would |
| 5553 | // not produce a false positive; it may of course produce a |
| 5554 | // false negative, in which case we would take the ArraySet |
| 5555 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5556 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5557 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5558 | __ movl(temp, Address(array, class_offset)); |
| 5559 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5560 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5561 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5562 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5563 | __ movl(temp, Address(temp, component_offset)); |
| 5564 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5565 | // nor the object reference in `register_value->klass`, as |
| 5566 | // we are comparing two poisoned references. |
| 5567 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5568 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5569 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5570 | NearLabel do_put; |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5571 | __ j(kEqual, &do_put); |
| 5572 | // If heap poisoning is enabled, the `temp` reference has |
| 5573 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5574 | __ MaybeUnpoisonHeapReference(temp); |
| 5575 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5576 | // If heap poisoning is enabled, no need to unpoison the |
| 5577 | // heap reference loaded below, as it is only used for a |
| 5578 | // comparison with null. |
| 5579 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5580 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5581 | __ Bind(&do_put); |
| 5582 | } else { |
| 5583 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5584 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5585 | } |
| 5586 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5587 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 5588 | codegen_->MarkGCCard( |
| 5589 | temp, card, array, value.AsRegister<CpuRegister>(), /* value_can_be_null= */ false); |
| 5590 | |
| 5591 | if (can_value_be_null) { |
| 5592 | DCHECK(do_store.IsLinked()); |
| 5593 | __ Bind(&do_store); |
| 5594 | } |
| 5595 | |
| 5596 | Location source = value; |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5597 | if (kPoisonHeapReferences) { |
| 5598 | __ movl(temp, register_value); |
| 5599 | __ PoisonHeapReference(temp); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5600 | source = temp_loc; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5601 | } |
| 5602 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5603 | __ movl(address, source.AsRegister<CpuRegister>()); |
| 5604 | |
| 5605 | if (can_value_be_null || !needs_type_check) { |
| 5606 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5607 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5608 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5609 | if (slow_path != nullptr) { |
| 5610 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | break; |
| 5614 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5615 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5616 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5617 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5618 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5619 | if (value.IsRegister()) { |
| 5620 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 5621 | } else { |
| 5622 | DCHECK(value.IsConstant()) << value; |
| 5623 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5624 | __ movl(address, Immediate(v)); |
| 5625 | } |
| 5626 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5627 | break; |
| 5628 | } |
| 5629 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5630 | case DataType::Type::kInt64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5631 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5632 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5633 | if (value.IsRegister()) { |
| 5634 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5635 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5636 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5637 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5638 | Address address_high = |
| 5639 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5640 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5641 | } |
| 5642 | break; |
| 5643 | } |
| 5644 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5645 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5646 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5647 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5648 | if (value.IsFpuRegister()) { |
| 5649 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5650 | } else { |
| 5651 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5652 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5653 | __ movl(address, Immediate(v)); |
| 5654 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5655 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5656 | break; |
| 5657 | } |
| 5658 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5659 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5660 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5661 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5662 | if (value.IsFpuRegister()) { |
| 5663 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5664 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5665 | } else { |
| 5666 | int64_t v = |
| 5667 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5668 | Address address_high = |
| 5669 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5670 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5671 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5672 | break; |
| 5673 | } |
| 5674 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5675 | case DataType::Type::kUint32: |
| 5676 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5677 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5678 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5679 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5680 | } |
| 5681 | } |
| 5682 | |
| 5683 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5684 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5685 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5686 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5687 | if (!instruction->IsEmittedAtUseSite()) { |
| 5688 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5689 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5690 | } |
| 5691 | |
| 5692 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5693 | if (instruction->IsEmittedAtUseSite()) { |
| 5694 | return; |
| 5695 | } |
| 5696 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5697 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5698 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5699 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5700 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5701 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5702 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5703 | // Mask out most significant bit in case the array is String's array of char. |
| 5704 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5705 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5706 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5707 | } |
| 5708 | |
| 5709 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5710 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5711 | InvokeRuntimeCallingConvention calling_convention; |
| 5712 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5713 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5714 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5715 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5716 | HInstruction* length = instruction->InputAt(1); |
| 5717 | if (!length->IsEmittedAtUseSite()) { |
| 5718 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5719 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5720 | } |
| 5721 | |
| 5722 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5723 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5724 | Location index_loc = locations->InAt(0); |
| 5725 | Location length_loc = locations->InAt(1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5726 | SlowPathCode* slow_path = |
| 5727 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5728 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5729 | if (length_loc.IsConstant()) { |
| 5730 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5731 | if (index_loc.IsConstant()) { |
| 5732 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5733 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5734 | if (index < 0 || index >= length) { |
| 5735 | codegen_->AddSlowPath(slow_path); |
| 5736 | __ jmp(slow_path->GetEntryLabel()); |
| 5737 | } else { |
| 5738 | // Some optimization after BCE may have generated this, and we should not |
| 5739 | // generate a bounds check if it is a valid range. |
| 5740 | } |
| 5741 | return; |
| 5742 | } |
| 5743 | |
| 5744 | // We have to reverse the jump condition because the length is the constant. |
| 5745 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5746 | __ cmpl(index_reg, Immediate(length)); |
| 5747 | codegen_->AddSlowPath(slow_path); |
| 5748 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5749 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5750 | HInstruction* array_length = instruction->InputAt(1); |
| 5751 | if (array_length->IsEmittedAtUseSite()) { |
| 5752 | // Address the length field in the array. |
| 5753 | DCHECK(array_length->IsArrayLength()); |
| 5754 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5755 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5756 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5757 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5758 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5759 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5760 | CpuRegister length_reg = CpuRegister(TMP); |
| 5761 | __ movl(length_reg, array_len); |
| 5762 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5763 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5764 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5765 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5766 | // Checking the bound for general case: |
| 5767 | // Array of char or String's array when the compression feature off. |
| 5768 | if (index_loc.IsConstant()) { |
| 5769 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5770 | __ cmpl(array_len, Immediate(value)); |
| 5771 | } else { |
| 5772 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5773 | } |
| 5774 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5775 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5776 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5777 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5778 | } |
| 5779 | codegen_->AddSlowPath(slow_path); |
| 5780 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5781 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5785 | CpuRegister card, |
| 5786 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5787 | CpuRegister value, |
| 5788 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5789 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5790 | if (value_can_be_null) { |
| 5791 | __ testl(value, value); |
| 5792 | __ j(kEqual, &is_null); |
| 5793 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5794 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5795 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5796 | /* no_rip= */ true)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5797 | // Calculate the offset (in the card table) of the card corresponding to |
| 5798 | // `object`. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5799 | __ movq(temp, object); |
| 5800 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5801 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5802 | // `object`'s card. |
| 5803 | // |
| 5804 | // Register `card` contains the address of the card table. Note that the card |
| 5805 | // table's base is biased during its creation so that it always starts at an |
| 5806 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5807 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5808 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5809 | // (located at `card + object >> kCardShift`). |
| 5810 | // |
| 5811 | // This dual use of the value in register `card` (1. to calculate the location |
| 5812 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5813 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5814 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5815 | if (value_can_be_null) { |
| 5816 | __ Bind(&is_null); |
| 5817 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5818 | } |
| 5819 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5820 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5821 | LOG(FATAL) << "Unimplemented"; |
| 5822 | } |
| 5823 | |
| 5824 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5825 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5826 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5827 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5828 | // The back edge will generate the suspend check. |
| 5829 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5830 | } |
| 5831 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5832 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5833 | } |
| 5834 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5835 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5836 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5837 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5838 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5839 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5840 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5841 | locations->SetCustomSlowPathCallerSaves( |
| 5842 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5843 | } |
| 5844 | |
| 5845 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5846 | HBasicBlock* block = instruction->GetBlock(); |
| 5847 | if (block->GetLoopInformation() != nullptr) { |
| 5848 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5849 | // The back edge will generate the suspend check. |
| 5850 | return; |
| 5851 | } |
| 5852 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5853 | // The goto will generate the suspend check. |
| 5854 | return; |
| 5855 | } |
| 5856 | GenerateSuspendCheck(instruction, nullptr); |
| 5857 | } |
| 5858 | |
| 5859 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5860 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5861 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5862 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5863 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5864 | slow_path = |
| 5865 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86_64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5866 | instruction->SetSlowPath(slow_path); |
| 5867 | codegen_->AddSlowPath(slow_path); |
| 5868 | if (successor != nullptr) { |
| 5869 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5870 | } |
| 5871 | } else { |
| 5872 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5873 | } |
| 5874 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5875 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5876 | /* no_rip= */ true), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5877 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5878 | if (successor == nullptr) { |
| 5879 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5880 | __ Bind(slow_path->GetReturnLabel()); |
| 5881 | } else { |
| 5882 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5883 | __ jmp(slow_path->GetEntryLabel()); |
| 5884 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5885 | } |
| 5886 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5887 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5888 | return codegen_->GetAssembler(); |
| 5889 | } |
| 5890 | |
| 5891 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5892 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5893 | Location source = move->GetSource(); |
| 5894 | Location destination = move->GetDestination(); |
| 5895 | |
| 5896 | if (source.IsRegister()) { |
| 5897 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5898 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5899 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5900 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5901 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5902 | } else { |
| 5903 | DCHECK(destination.IsDoubleStackSlot()); |
| 5904 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5905 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5906 | } |
| 5907 | } else if (source.IsStackSlot()) { |
| 5908 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5909 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5910 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5911 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5912 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5913 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5914 | } else { |
| 5915 | DCHECK(destination.IsStackSlot()); |
| 5916 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5917 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5918 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5919 | } else if (source.IsDoubleStackSlot()) { |
| 5920 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5921 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5922 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5923 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5924 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5925 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5926 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5927 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5928 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5929 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5930 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5931 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5932 | if (destination.IsFpuRegister()) { |
| 5933 | __ movups(destination.AsFpuRegister<XmmRegister>(), |
| 5934 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5935 | } else { |
| 5936 | DCHECK(destination.IsSIMDStackSlot()); |
| 5937 | size_t high = kX86_64WordSize; |
| 5938 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5939 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5940 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex() + high)); |
| 5941 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex() + high), CpuRegister(TMP)); |
| 5942 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5943 | } else if (source.IsConstant()) { |
| 5944 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5945 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5946 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5947 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5948 | if (value == 0) { |
| 5949 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5950 | } else { |
| 5951 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5952 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5953 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5954 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5955 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5956 | } |
| 5957 | } else if (constant->IsLongConstant()) { |
| 5958 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5959 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5960 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5961 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5962 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5963 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5964 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5965 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5966 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5967 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5968 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5969 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5970 | } else { |
| 5971 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5972 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5973 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5974 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5975 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5976 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5977 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5978 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5979 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5980 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5981 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5982 | } else { |
| 5983 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5984 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5985 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5986 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5987 | } else if (source.IsFpuRegister()) { |
| 5988 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5989 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5990 | } else if (destination.IsStackSlot()) { |
| 5991 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5992 | source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5993 | } else if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5994 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5995 | source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5996 | } else { |
| 5997 | DCHECK(destination.IsSIMDStackSlot()); |
| 5998 | __ movups(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 5999 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6000 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6001 | } |
| 6002 | } |
| 6003 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 6004 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6005 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 6006 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 6007 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6008 | } |
| 6009 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 6010 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 6011 | __ movq(CpuRegister(TMP), reg1); |
| 6012 | __ movq(reg1, reg2); |
| 6013 | __ movq(reg2, CpuRegister(TMP)); |
| 6014 | } |
| 6015 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 6016 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 6017 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 6018 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 6019 | __ movq(reg, CpuRegister(TMP)); |
| 6020 | } |
| 6021 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6022 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 6023 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 6024 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 6025 | __ movd(reg, CpuRegister(TMP)); |
| 6026 | } |
| 6027 | |
| 6028 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 6029 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 6030 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 6031 | __ movd(reg, CpuRegister(TMP)); |
| 6032 | } |
| 6033 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6034 | void ParallelMoveResolverX86_64::Exchange128(XmmRegister reg, int mem) { |
| 6035 | size_t extra_slot = 2 * kX86_64WordSize; |
| 6036 | __ subq(CpuRegister(RSP), Immediate(extra_slot)); |
| 6037 | __ movups(Address(CpuRegister(RSP), 0), XmmRegister(reg)); |
| 6038 | ExchangeMemory64(0, mem + extra_slot, 2); |
| 6039 | __ movups(XmmRegister(reg), Address(CpuRegister(RSP), 0)); |
| 6040 | __ addq(CpuRegister(RSP), Immediate(extra_slot)); |
| 6041 | } |
| 6042 | |
| 6043 | void ParallelMoveResolverX86_64::ExchangeMemory32(int mem1, int mem2) { |
| 6044 | ScratchRegisterScope ensure_scratch( |
| 6045 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 6046 | |
| 6047 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 6048 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 6049 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 6050 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 6051 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 6052 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 6053 | CpuRegister(ensure_scratch.GetRegister())); |
| 6054 | } |
| 6055 | |
| 6056 | void ParallelMoveResolverX86_64::ExchangeMemory64(int mem1, int mem2, int num_of_qwords) { |
| 6057 | ScratchRegisterScope ensure_scratch( |
| 6058 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 6059 | |
| 6060 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 6061 | |
| 6062 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 6063 | for (int i = 0; i < num_of_qwords; i++) { |
| 6064 | __ movq(CpuRegister(TMP), |
| 6065 | Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 6066 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 6067 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 6068 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), |
| 6069 | CpuRegister(TMP)); |
| 6070 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 6071 | CpuRegister(ensure_scratch.GetRegister())); |
| 6072 | stack_offset += kX86_64WordSize; |
| 6073 | } |
| 6074 | } |
| 6075 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6076 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6077 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6078 | Location source = move->GetSource(); |
| 6079 | Location destination = move->GetDestination(); |
| 6080 | |
| 6081 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 6082 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6083 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6084 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6085 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6086 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6087 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6088 | ExchangeMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 6089 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6090 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 6091 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6092 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 6093 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6094 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6095 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6096 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 6097 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 6098 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6099 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6100 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6101 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6102 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6103 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6104 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6105 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6106 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6107 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 6108 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 6109 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 6110 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 6111 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 6112 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6113 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6114 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 6115 | } |
| 6116 | } |
| 6117 | |
| 6118 | |
| 6119 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 6120 | __ pushq(CpuRegister(reg)); |
| 6121 | } |
| 6122 | |
| 6123 | |
| 6124 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 6125 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6126 | } |
| 6127 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6128 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6129 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6130 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 6131 | const size_t status_byte_offset = |
| 6132 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 6133 | constexpr uint32_t shifted_visibly_initialized_value = |
| 6134 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6135 | |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 6136 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6137 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6138 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6139 | } |
| 6140 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6141 | void InstructionCodeGeneratorX86_64::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 6142 | CpuRegister temp) { |
| 6143 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 6144 | uint32_t mask = check->GetBitstringMask(); |
| 6145 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 6146 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 6147 | |
| 6148 | if (mask_bits == 16u) { |
| 6149 | // Compare the bitstring in memory. |
| 6150 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 6151 | } else { |
| 6152 | // /* uint32_t */ temp = temp->status_ |
| 6153 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 6154 | // Compare the bitstring bits using SUB. |
| 6155 | __ subl(temp, Immediate(path_to_root)); |
| 6156 | // Shift out bits that do not contribute to the comparison. |
| 6157 | __ shll(temp, Immediate(32u - mask_bits)); |
| 6158 | } |
| 6159 | } |
| 6160 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6161 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 6162 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6163 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6164 | case HLoadClass::LoadKind::kInvalid: |
| 6165 | LOG(FATAL) << "UNREACHABLE"; |
| 6166 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6167 | case HLoadClass::LoadKind::kReferrersClass: |
| 6168 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6169 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6170 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6171 | case HLoadClass::LoadKind::kBssEntry: |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6172 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 6173 | case HLoadClass::LoadKind::kBssEntryPackage: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6174 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6175 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6176 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6177 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6178 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6179 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6180 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6181 | break; |
| 6182 | } |
| 6183 | return desired_class_load_kind; |
| 6184 | } |
| 6185 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6186 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6187 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6188 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6189 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6190 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6191 | cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6192 | Location::RegisterLocation(RAX), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6193 | Location::RegisterLocation(RAX)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6194 | return; |
| 6195 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6196 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 6197 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 6198 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6199 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6200 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 6201 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6202 | ? LocationSummary::kCallOnSlowPath |
| 6203 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6204 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6205 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6206 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6207 | } |
| 6208 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6209 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6210 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6211 | } |
| 6212 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6213 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 6214 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 6215 | // Rely on the type resolution and/or initialization to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6216 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6217 | } else { |
| 6218 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6219 | } |
| 6220 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6221 | } |
| 6222 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6223 | Label* CodeGeneratorX86_64::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6224 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6225 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6226 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6227 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6228 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6229 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 6230 | return &info->label; |
| 6231 | } |
| 6232 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6233 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6234 | // move. |
| 6235 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6236 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6237 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6238 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6239 | return; |
| 6240 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6241 | DCHECK_EQ(cls->NeedsAccessCheck(), |
| 6242 | load_kind == HLoadClass::LoadKind::kBssEntryPublic || |
| 6243 | load_kind == HLoadClass::LoadKind::kBssEntryPackage); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6244 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6245 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6246 | Location out_loc = locations->Out(); |
| 6247 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6248 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6249 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 6250 | ? kWithoutReadBarrier |
| 6251 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6252 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6253 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6254 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6255 | DCHECK(!cls->CanCallRuntime()); |
| 6256 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6257 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6258 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6259 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6260 | cls, |
| 6261 | out_loc, |
| 6262 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6263 | /* fixup_label= */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6264 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6265 | break; |
| 6266 | } |
| 6267 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6268 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6269 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6270 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6271 | __ leal(out, |
| 6272 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6273 | codegen_->RecordBootImageTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6274 | break; |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6275 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6276 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6277 | __ movl(out, |
| 6278 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 6279 | codegen_->RecordBootImageRelRoPatch(CodeGenerator::GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6280 | break; |
| 6281 | } |
Vladimir Marko | 8f63f10 | 2020-09-28 12:10:28 +0100 | [diff] [blame] | 6282 | case HLoadClass::LoadKind::kBssEntry: |
| 6283 | case HLoadClass::LoadKind::kBssEntryPublic: |
| 6284 | case HLoadClass::LoadKind::kBssEntryPackage: { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6285 | Address address = Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6286 | /* no_rip= */ false); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6287 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6288 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 6289 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6290 | // No need for memory fence, thanks to the x86-64 memory model. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6291 | generate_null_check = true; |
| 6292 | break; |
| 6293 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6294 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 6295 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6296 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 6297 | DCHECK_NE(address, 0u); |
| 6298 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| 6299 | break; |
| 6300 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6301 | case HLoadClass::LoadKind::kJitTableAddress: { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6302 | Address address = Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6303 | /* no_rip= */ true); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6304 | Label* fixup_label = |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6305 | codegen_->NewJitRootClassPatch(cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6306 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6307 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6308 | break; |
| 6309 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6310 | default: |
| 6311 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 6312 | UNREACHABLE(); |
| 6313 | } |
| 6314 | |
| 6315 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6316 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6317 | SlowPathCode* slow_path = |
| 6318 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6319 | codegen_->AddSlowPath(slow_path); |
| 6320 | if (generate_null_check) { |
| 6321 | __ testl(out, out); |
| 6322 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6323 | } |
| 6324 | if (cls->MustGenerateClinitCheck()) { |
| 6325 | GenerateClassInitializationCheck(slow_path, out); |
| 6326 | } else { |
| 6327 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6328 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6329 | } |
| 6330 | } |
| 6331 | |
| 6332 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 6333 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6334 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6335 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6336 | if (check->HasUses()) { |
| 6337 | locations->SetOut(Location::SameAsFirstInput()); |
| 6338 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6339 | // Rely on the type initialization to save everything we need. |
| 6340 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6341 | } |
| 6342 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6343 | void LocationsBuilderX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6344 | // Custom calling convention: RAX serves as both input and output. |
| 6345 | Location location = Location::RegisterLocation(RAX); |
| 6346 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 6347 | } |
| 6348 | |
| 6349 | void InstructionCodeGeneratorX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6350 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 6351 | } |
| 6352 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6353 | void LocationsBuilderX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 6354 | // Custom calling convention: RAX serves as both input and output. |
| 6355 | Location location = Location::RegisterLocation(RAX); |
| 6356 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 6357 | } |
| 6358 | |
| 6359 | void InstructionCodeGeneratorX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 6360 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 6361 | } |
| 6362 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6363 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6364 | // We assume the class to not be null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6365 | SlowPathCode* slow_path = |
| 6366 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64(check->GetLoadClass(), check); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6367 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6368 | GenerateClassInitializationCheck(slow_path, |
| 6369 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6370 | } |
| 6371 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6372 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 6373 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6374 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6375 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6376 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6377 | case HLoadString::LoadKind::kBssEntry: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6378 | DCHECK(!GetCompilerOptions().IsJitCompiler()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6379 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6380 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6381 | case HLoadString::LoadKind::kJitTableAddress: |
Vladimir Marko | 695348f | 2020-05-19 14:42:02 +0100 | [diff] [blame] | 6382 | DCHECK(GetCompilerOptions().IsJitCompiler()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6383 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6384 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6385 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6386 | } |
| 6387 | return desired_string_load_kind; |
| 6388 | } |
| 6389 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6390 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6391 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6392 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6393 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6394 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 6395 | } else { |
| 6396 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6397 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 6398 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6399 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6400 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6401 | } else { |
| 6402 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6403 | } |
| 6404 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6405 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6406 | } |
| 6407 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6408 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6409 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6410 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6411 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6412 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6413 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6414 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6415 | return &info->label; |
| 6416 | } |
| 6417 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6418 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6419 | // move. |
| 6420 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6421 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6422 | Location out_loc = locations->Out(); |
| 6423 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6424 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6425 | switch (load->GetLoadKind()) { |
| 6426 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6427 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6428 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6429 | __ leal(out, |
| 6430 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6431 | codegen_->RecordBootImageStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6432 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6433 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6434 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6435 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6436 | __ movl(out, |
| 6437 | Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | de91ca9 | 2020-10-27 13:41:40 +0000 | [diff] [blame] | 6438 | codegen_->RecordBootImageRelRoPatch(CodeGenerator::GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6439 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6440 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6441 | case HLoadString::LoadKind::kBssEntry: { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6442 | Address address = Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6443 | /* no_rip= */ false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6444 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 6445 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6446 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6447 | // No need for memory fence, thanks to the x86-64 memory model. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6448 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86_64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6449 | codegen_->AddSlowPath(slow_path); |
| 6450 | __ testl(out, out); |
| 6451 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6452 | __ Bind(slow_path->GetExitLabel()); |
| 6453 | return; |
| 6454 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6455 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 6456 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 6457 | DCHECK_NE(address, 0u); |
| 6458 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| 6459 | return; |
| 6460 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6461 | case HLoadString::LoadKind::kJitTableAddress: { |
Vladimir Marko | 4ef451a | 2020-07-23 09:54:27 +0000 | [diff] [blame] | 6462 | Address address = Address::Absolute(CodeGeneratorX86_64::kPlaceholder32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6463 | /* no_rip= */ true); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6464 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 6465 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6466 | // /* GcRoot<mirror::String> */ out = *address |
| 6467 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6468 | return; |
| 6469 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6470 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6471 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6472 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6473 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6474 | // 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] | 6475 | // Custom calling convention: RAX serves as both input and output. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6476 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6477 | codegen_->InvokeRuntime(kQuickResolveString, |
| 6478 | load, |
| 6479 | load->GetDexPc()); |
| 6480 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6481 | } |
| 6482 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6483 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6484 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6485 | /* no_rip= */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6486 | } |
| 6487 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6488 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 6489 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6490 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6491 | locations->SetOut(Location::RequiresRegister()); |
| 6492 | } |
| 6493 | |
| 6494 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6495 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 6496 | } |
| 6497 | |
| 6498 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6499 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6503 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6504 | } |
| 6505 | |
| 6506 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6507 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6508 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6509 | InvokeRuntimeCallingConvention calling_convention; |
| 6510 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6511 | } |
| 6512 | |
| 6513 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6514 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6515 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6516 | } |
| 6517 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6518 | // Temp is used for read barrier. |
| 6519 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6520 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6521 | !kUseBakerReadBarrier && |
| 6522 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6523 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6524 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6525 | return 1; |
| 6526 | } |
| 6527 | return 0; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6528 | } |
| 6529 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6530 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 6531 | // interface pointer, the current interface is compared in memory. |
| 6532 | // The other checks have one temp for loading the object's class. |
| 6533 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6534 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6535 | return 2; |
| 6536 | } |
| 6537 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6538 | } |
| 6539 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6540 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6541 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6542 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6543 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6544 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6545 | case TypeCheckKind::kExactCheck: |
| 6546 | case TypeCheckKind::kAbstractClassCheck: |
| 6547 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6548 | case TypeCheckKind::kArrayObjectCheck: { |
| 6549 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6550 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6551 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6552 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6553 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6554 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6555 | case TypeCheckKind::kUnresolvedCheck: |
| 6556 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6557 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6558 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6559 | case TypeCheckKind::kBitstringCheck: |
| 6560 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6561 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6562 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6563 | LocationSummary* locations = |
| 6564 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6565 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6566 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6567 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6568 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6569 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6570 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6571 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6572 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 6573 | } else { |
| 6574 | locations->SetInAt(1, Location::Any()); |
| 6575 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6576 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 6577 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6578 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6579 | } |
| 6580 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6581 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6582 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6583 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6584 | Location obj_loc = locations->InAt(0); |
| 6585 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6586 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6587 | Location out_loc = locations->Out(); |
| 6588 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6589 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6590 | DCHECK_LE(num_temps, 1u); |
| 6591 | Location maybe_temp_loc = (num_temps >= 1u) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6592 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6593 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6594 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6595 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6596 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6597 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6598 | |
| 6599 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6600 | // Avoid null check if we know obj is not null. |
| 6601 | if (instruction->MustDoNullCheck()) { |
| 6602 | __ testl(obj, obj); |
| 6603 | __ j(kEqual, &zero); |
| 6604 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6605 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6606 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6607 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6608 | ReadBarrierOption read_barrier_option = |
| 6609 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6610 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6611 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6612 | out_loc, |
| 6613 | obj_loc, |
| 6614 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6615 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6616 | if (cls.IsRegister()) { |
| 6617 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6618 | } else { |
| 6619 | DCHECK(cls.IsStackSlot()) << cls; |
| 6620 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6621 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6622 | if (zero.IsLinked()) { |
| 6623 | // Classes must be equal for the instanceof to succeed. |
| 6624 | __ j(kNotEqual, &zero); |
| 6625 | __ movl(out, Immediate(1)); |
| 6626 | __ jmp(&done); |
| 6627 | } else { |
| 6628 | __ setcc(kEqual, out); |
| 6629 | // setcc only sets the low byte. |
| 6630 | __ andl(out, Immediate(1)); |
| 6631 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6632 | break; |
| 6633 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6634 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6635 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6636 | ReadBarrierOption read_barrier_option = |
| 6637 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6638 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6639 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6640 | out_loc, |
| 6641 | obj_loc, |
| 6642 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6643 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6644 | // If the class is abstract, we eagerly fetch the super class of the |
| 6645 | // object to avoid doing a comparison we know will fail. |
| 6646 | NearLabel loop, success; |
| 6647 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6648 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6649 | GenerateReferenceLoadOneRegister(instruction, |
| 6650 | out_loc, |
| 6651 | super_offset, |
| 6652 | maybe_temp_loc, |
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 | __ testl(out, out); |
| 6655 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6656 | __ j(kEqual, &done); |
| 6657 | if (cls.IsRegister()) { |
| 6658 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6659 | } else { |
| 6660 | DCHECK(cls.IsStackSlot()) << cls; |
| 6661 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6662 | } |
| 6663 | __ j(kNotEqual, &loop); |
| 6664 | __ movl(out, Immediate(1)); |
| 6665 | if (zero.IsLinked()) { |
| 6666 | __ jmp(&done); |
| 6667 | } |
| 6668 | break; |
| 6669 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6670 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6671 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6672 | ReadBarrierOption read_barrier_option = |
| 6673 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6674 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6675 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6676 | out_loc, |
| 6677 | obj_loc, |
| 6678 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6679 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6680 | // Walk over the class hierarchy to find a match. |
| 6681 | NearLabel loop, success; |
| 6682 | __ Bind(&loop); |
| 6683 | if (cls.IsRegister()) { |
| 6684 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6685 | } else { |
| 6686 | DCHECK(cls.IsStackSlot()) << cls; |
| 6687 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6688 | } |
| 6689 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6690 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6691 | GenerateReferenceLoadOneRegister(instruction, |
| 6692 | out_loc, |
| 6693 | super_offset, |
| 6694 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6695 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6696 | __ testl(out, out); |
| 6697 | __ j(kNotEqual, &loop); |
| 6698 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6699 | __ jmp(&done); |
| 6700 | __ Bind(&success); |
| 6701 | __ movl(out, Immediate(1)); |
| 6702 | if (zero.IsLinked()) { |
| 6703 | __ jmp(&done); |
| 6704 | } |
| 6705 | break; |
| 6706 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6707 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6708 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6709 | ReadBarrierOption read_barrier_option = |
| 6710 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6711 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6712 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6713 | out_loc, |
| 6714 | obj_loc, |
| 6715 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6716 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6717 | // Do an exact check. |
| 6718 | NearLabel exact_check; |
| 6719 | if (cls.IsRegister()) { |
| 6720 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6721 | } else { |
| 6722 | DCHECK(cls.IsStackSlot()) << cls; |
| 6723 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6724 | } |
| 6725 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6726 | // 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] | 6727 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6728 | GenerateReferenceLoadOneRegister(instruction, |
| 6729 | out_loc, |
| 6730 | component_offset, |
| 6731 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6732 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6733 | __ testl(out, out); |
| 6734 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6735 | __ j(kEqual, &done); |
| 6736 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6737 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6738 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6739 | __ movl(out, Immediate(1)); |
| 6740 | __ jmp(&done); |
| 6741 | break; |
| 6742 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6743 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6744 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6745 | // No read barrier since the slow path will retry upon failure. |
| 6746 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6747 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6748 | out_loc, |
| 6749 | obj_loc, |
| 6750 | class_offset, |
| 6751 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6752 | if (cls.IsRegister()) { |
| 6753 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6754 | } else { |
| 6755 | DCHECK(cls.IsStackSlot()) << cls; |
| 6756 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6757 | } |
| 6758 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6759 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6760 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6761 | codegen_->AddSlowPath(slow_path); |
| 6762 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6763 | __ movl(out, Immediate(1)); |
| 6764 | if (zero.IsLinked()) { |
| 6765 | __ jmp(&done); |
| 6766 | } |
| 6767 | break; |
| 6768 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6769 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6770 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6771 | case TypeCheckKind::kInterfaceCheck: { |
| 6772 | // 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] | 6773 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6774 | // cases. |
| 6775 | // |
| 6776 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6777 | // entry point without resorting to a type checking slow path |
| 6778 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6779 | // require to assign fixed registers for the inputs of this |
| 6780 | // HInstanceOf instruction (following the runtime calling |
| 6781 | // convention), which might be cluttered by the potential first |
| 6782 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6783 | // |
| 6784 | // TODO: Introduce a new runtime entry point taking the object |
| 6785 | // to test (instead of its class) as argument, and let it deal |
| 6786 | // with the read barrier issues. This will let us refactor this |
| 6787 | // case of the `switch` code as it was previously (with a direct |
| 6788 | // call to the runtime not using a type checking slow path). |
| 6789 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6790 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6791 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6792 | instruction, /* is_fatal= */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6793 | codegen_->AddSlowPath(slow_path); |
| 6794 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6795 | if (zero.IsLinked()) { |
| 6796 | __ jmp(&done); |
| 6797 | } |
| 6798 | break; |
| 6799 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6800 | |
| 6801 | case TypeCheckKind::kBitstringCheck: { |
| 6802 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6803 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6804 | out_loc, |
| 6805 | obj_loc, |
| 6806 | class_offset, |
| 6807 | kWithoutReadBarrier); |
| 6808 | |
| 6809 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 6810 | if (zero.IsLinked()) { |
| 6811 | __ j(kNotEqual, &zero); |
| 6812 | __ movl(out, Immediate(1)); |
| 6813 | __ jmp(&done); |
| 6814 | } else { |
| 6815 | __ setcc(kEqual, out); |
| 6816 | // setcc only sets the low byte. |
| 6817 | __ andl(out, Immediate(1)); |
| 6818 | } |
| 6819 | break; |
| 6820 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6821 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6822 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6823 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6824 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6825 | __ xorl(out, out); |
| 6826 | } |
| 6827 | |
| 6828 | if (done.IsLinked()) { |
| 6829 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6830 | } |
| 6831 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6832 | if (slow_path != nullptr) { |
| 6833 | __ Bind(slow_path->GetExitLabel()); |
| 6834 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6835 | } |
| 6836 | |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6837 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6838 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6839 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6840 | LocationSummary* locations = |
| 6841 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6842 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6843 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6844 | // Require a register for the interface check since there is a loop that compares the class to |
| 6845 | // a memory address. |
| 6846 | locations->SetInAt(1, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6847 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6848 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6849 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6850 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6851 | } else { |
| 6852 | locations->SetInAt(1, Location::Any()); |
| 6853 | } |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6854 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathX86. |
| 6855 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6856 | } |
| 6857 | |
| 6858 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6859 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6860 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6861 | Location obj_loc = locations->InAt(0); |
| 6862 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6863 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6864 | Location temp_loc = locations->GetTemp(0); |
| 6865 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6866 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6867 | DCHECK_GE(num_temps, 1u); |
| 6868 | DCHECK_LE(num_temps, 2u); |
| 6869 | Location maybe_temp2_loc = (num_temps >= 2u) ? locations->GetTemp(1) : Location::NoLocation(); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6870 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6871 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6872 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6873 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6874 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6875 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6876 | const uint32_t object_array_data_offset = |
| 6877 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6878 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6879 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6880 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6881 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6882 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6883 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6884 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6885 | |
| 6886 | NearLabel done; |
| 6887 | // Avoid null check if we know obj is not null. |
| 6888 | if (instruction->MustDoNullCheck()) { |
| 6889 | __ testl(obj, obj); |
| 6890 | __ j(kEqual, &done); |
| 6891 | } |
| 6892 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6893 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6894 | case TypeCheckKind::kExactCheck: |
| 6895 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6896 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6897 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6898 | temp_loc, |
| 6899 | obj_loc, |
| 6900 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6901 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6902 | if (cls.IsRegister()) { |
| 6903 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6904 | } else { |
| 6905 | DCHECK(cls.IsStackSlot()) << cls; |
| 6906 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6907 | } |
| 6908 | // Jump to slow path for throwing the exception or doing a |
| 6909 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6910 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6911 | break; |
| 6912 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6913 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6914 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6915 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6916 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6917 | temp_loc, |
| 6918 | obj_loc, |
| 6919 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6920 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6921 | // If the class is abstract, we eagerly fetch the super class of the |
| 6922 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6923 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6924 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6925 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6926 | GenerateReferenceLoadOneRegister(instruction, |
| 6927 | temp_loc, |
| 6928 | super_offset, |
| 6929 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6930 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6931 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6932 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6933 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6934 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6935 | // Otherwise, compare the classes. |
| 6936 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6937 | if (cls.IsRegister()) { |
| 6938 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6939 | } else { |
| 6940 | DCHECK(cls.IsStackSlot()) << cls; |
| 6941 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6942 | } |
| 6943 | __ j(kNotEqual, &loop); |
| 6944 | break; |
| 6945 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6946 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6947 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6948 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6949 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6950 | temp_loc, |
| 6951 | obj_loc, |
| 6952 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6953 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6954 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6955 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6956 | __ Bind(&loop); |
| 6957 | if (cls.IsRegister()) { |
| 6958 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6959 | } else { |
| 6960 | DCHECK(cls.IsStackSlot()) << cls; |
| 6961 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6962 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6963 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6964 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6965 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6966 | GenerateReferenceLoadOneRegister(instruction, |
| 6967 | temp_loc, |
| 6968 | super_offset, |
| 6969 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6970 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6971 | |
| 6972 | // If the class reference currently in `temp` is not null, jump |
| 6973 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6974 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6975 | __ j(kNotZero, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6976 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6977 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6978 | break; |
| 6979 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6980 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6981 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6982 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6983 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6984 | temp_loc, |
| 6985 | obj_loc, |
| 6986 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6987 | kWithoutReadBarrier); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6988 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6989 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6990 | if (cls.IsRegister()) { |
| 6991 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6992 | } else { |
| 6993 | DCHECK(cls.IsStackSlot()) << cls; |
| 6994 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6995 | } |
| 6996 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6997 | |
| 6998 | // 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] | 6999 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7000 | GenerateReferenceLoadOneRegister(instruction, |
| 7001 | temp_loc, |
| 7002 | component_offset, |
| 7003 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7004 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7005 | |
| 7006 | // If the component type is not null (i.e. the object is indeed |
| 7007 | // an array), jump to label `check_non_primitive_component_type` |
| 7008 | // to further check that this component type is not a primitive |
| 7009 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7010 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7011 | // Otherwise, jump to the slow path to throw the exception. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7012 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7013 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7014 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7015 | break; |
| 7016 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7017 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7018 | case TypeCheckKind::kUnresolvedCheck: { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 7019 | // 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] | 7020 | // |
| 7021 | // We cannot directly call the CheckCast runtime entry point |
| 7022 | // without resorting to a type checking slow path here (i.e. by |
| 7023 | // calling InvokeRuntime directly), as it would require to |
| 7024 | // assign fixed registers for the inputs of this HInstanceOf |
| 7025 | // instruction (following the runtime calling convention), which |
| 7026 | // might be cluttered by the potential first read barrier |
| 7027 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7028 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7029 | break; |
| 7030 | } |
| 7031 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7032 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7033 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 7034 | // We can not get false positives by doing this. |
| 7035 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7036 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7037 | temp_loc, |
| 7038 | obj_loc, |
| 7039 | class_offset, |
| 7040 | kWithoutReadBarrier); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 7041 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7042 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7043 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7044 | temp_loc, |
| 7045 | temp_loc, |
| 7046 | iftable_offset, |
| 7047 | kWithoutReadBarrier); |
| 7048 | // Iftable is never null. |
| 7049 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
| 7050 | // Maybe poison the `cls` for direct comparison with memory. |
| 7051 | __ MaybePoisonHeapReference(cls.AsRegister<CpuRegister>()); |
| 7052 | // Loop through the iftable and check if any class matches. |
| 7053 | NearLabel start_loop; |
| 7054 | __ Bind(&start_loop); |
| 7055 | // Need to subtract first to handle the empty array case. |
| 7056 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| 7057 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 7058 | // Go to next interface if the classes do not match. |
| 7059 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 7060 | CodeGeneratorX86_64::ArrayAddress(temp, |
| 7061 | maybe_temp2_loc, |
| 7062 | TIMES_4, |
| 7063 | object_array_data_offset)); |
| 7064 | __ j(kNotEqual, &start_loop); // Return if same class. |
| 7065 | // If `cls` was poisoned above, unpoison it. |
| 7066 | __ MaybeUnpoisonHeapReference(cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7067 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7068 | } |
| 7069 | |
| 7070 | case TypeCheckKind::kBitstringCheck: { |
| 7071 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7072 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7073 | temp_loc, |
| 7074 | obj_loc, |
| 7075 | class_offset, |
| 7076 | kWithoutReadBarrier); |
| 7077 | |
| 7078 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 7079 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 7080 | break; |
| 7081 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7082 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7083 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7084 | if (done.IsLinked()) { |
| 7085 | __ Bind(&done); |
| 7086 | } |
| 7087 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7088 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7089 | } |
| 7090 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7091 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7092 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7093 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7094 | InvokeRuntimeCallingConvention calling_convention; |
| 7095 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 7096 | } |
| 7097 | |
| 7098 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7099 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7100 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7101 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7102 | if (instruction->IsEnter()) { |
| 7103 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 7104 | } else { |
| 7105 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 7106 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7107 | } |
| 7108 | |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 7109 | void LocationsBuilderX86_64::VisitX86AndNot(HX86AndNot* instruction) { |
| 7110 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 7111 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 7112 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 7113 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7114 | // There is no immediate variant of negated bitwise and in X86. |
| 7115 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7116 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7117 | } |
| 7118 | |
| 7119 | void LocationsBuilderX86_64::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* 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 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 7125 | } |
| 7126 | |
| 7127 | void InstructionCodeGeneratorX86_64::VisitX86AndNot(HX86AndNot* instruction) { |
| 7128 | LocationSummary* locations = instruction->GetLocations(); |
| 7129 | Location first = locations->InAt(0); |
| 7130 | Location second = locations->InAt(1); |
| 7131 | Location dest = locations->Out(); |
| 7132 | __ andn(dest.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 7133 | } |
| 7134 | |
| 7135 | void InstructionCodeGeneratorX86_64::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 7136 | LocationSummary* locations = instruction->GetLocations(); |
| 7137 | Location src = locations->InAt(0); |
| 7138 | Location dest = locations->Out(); |
| 7139 | switch (instruction->GetOpKind()) { |
| 7140 | case HInstruction::kAnd: |
| 7141 | __ blsr(dest.AsRegister<CpuRegister>(), src.AsRegister<CpuRegister>()); |
| 7142 | break; |
| 7143 | case HInstruction::kXor: |
| 7144 | __ blsmsk(dest.AsRegister<CpuRegister>(), src.AsRegister<CpuRegister>()); |
| 7145 | break; |
| 7146 | default: |
| 7147 | LOG(FATAL) << "Unreachable"; |
| 7148 | } |
| 7149 | } |
| 7150 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7151 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 7152 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 7153 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 7154 | |
| 7155 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7156 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7157 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7158 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 7159 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7160 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 7161 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7162 | locations->SetOut(Location::SameAsFirstInput()); |
| 7163 | } |
| 7164 | |
| 7165 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 7166 | HandleBitwiseOperation(instruction); |
| 7167 | } |
| 7168 | |
| 7169 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 7170 | HandleBitwiseOperation(instruction); |
| 7171 | } |
| 7172 | |
| 7173 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 7174 | HandleBitwiseOperation(instruction); |
| 7175 | } |
| 7176 | |
| 7177 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 7178 | LocationSummary* locations = instruction->GetLocations(); |
| 7179 | Location first = locations->InAt(0); |
| 7180 | Location second = locations->InAt(1); |
| 7181 | DCHECK(first.Equals(locations->Out())); |
| 7182 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7183 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7184 | if (second.IsRegister()) { |
| 7185 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7186 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7187 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7188 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7189 | } else { |
| 7190 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7191 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7192 | } |
| 7193 | } else if (second.IsConstant()) { |
| 7194 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 7195 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7196 | __ andl(first.AsRegister<CpuRegister>(), imm); |
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>(), imm); |
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>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7202 | } |
| 7203 | } else { |
| 7204 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 7205 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7206 | __ andl(first.AsRegister<CpuRegister>(), address); |
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>(), address); |
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>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7212 | } |
| 7213 | } |
| 7214 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7215 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7216 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 7217 | bool second_is_constant = false; |
| 7218 | int64_t value = 0; |
| 7219 | if (second.IsConstant()) { |
| 7220 | second_is_constant = true; |
| 7221 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7222 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 7223 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7224 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7225 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7226 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 7227 | if (is_int32_value) { |
| 7228 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 7229 | } else { |
| 7230 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 7231 | } |
| 7232 | } else if (second.IsDoubleStackSlot()) { |
| 7233 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7234 | } else { |
| 7235 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 7236 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7237 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7238 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 7239 | if (is_int32_value) { |
| 7240 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 7241 | } else { |
| 7242 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 7243 | } |
| 7244 | } else if (second.IsDoubleStackSlot()) { |
| 7245 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7246 | } else { |
| 7247 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 7248 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7249 | } else { |
| 7250 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7251 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 7252 | if (is_int32_value) { |
| 7253 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 7254 | } else { |
| 7255 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 7256 | } |
| 7257 | } else if (second.IsDoubleStackSlot()) { |
| 7258 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7259 | } else { |
| 7260 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 7261 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7262 | } |
| 7263 | } |
| 7264 | } |
| 7265 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7266 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister( |
| 7267 | HInstruction* instruction, |
| 7268 | Location out, |
| 7269 | uint32_t offset, |
| 7270 | Location maybe_temp, |
| 7271 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7272 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7273 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7274 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7275 | if (kUseBakerReadBarrier) { |
| 7276 | // Load with fast path based Baker's read barrier. |
| 7277 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7278 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7279 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7280 | } else { |
| 7281 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7282 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7283 | // in the following move operation, as we will need it for the |
| 7284 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7285 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7286 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7287 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7288 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7289 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7290 | } |
| 7291 | } else { |
| 7292 | // Plain load with no read barrier. |
| 7293 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7294 | __ movl(out_reg, Address(out_reg, offset)); |
| 7295 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7296 | } |
| 7297 | } |
| 7298 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7299 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters( |
| 7300 | HInstruction* instruction, |
| 7301 | Location out, |
| 7302 | Location obj, |
| 7303 | uint32_t offset, |
| 7304 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7305 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 7306 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7307 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7308 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7309 | if (kUseBakerReadBarrier) { |
| 7310 | // Load with fast path based Baker's read barrier. |
| 7311 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7312 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7313 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7314 | } else { |
| 7315 | // Load with slow path based read barrier. |
| 7316 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7317 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7318 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7319 | } |
| 7320 | } else { |
| 7321 | // Plain load with no read barrier. |
| 7322 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7323 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7324 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7325 | } |
| 7326 | } |
| 7327 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7328 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad( |
| 7329 | HInstruction* instruction, |
| 7330 | Location root, |
| 7331 | const Address& address, |
| 7332 | Label* fixup_label, |
| 7333 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7334 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7335 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7336 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7337 | if (kUseBakerReadBarrier) { |
| 7338 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7339 | // Baker's read barrier are used: |
| 7340 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7341 | // root = obj.field; |
| 7342 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7343 | // if (temp != null) { |
| 7344 | // root = temp(root) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7345 | // } |
| 7346 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7347 | // /* GcRoot<mirror::Object> */ root = *address |
| 7348 | __ movl(root_reg, address); |
| 7349 | if (fixup_label != nullptr) { |
| 7350 | __ Bind(fixup_label); |
| 7351 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7352 | static_assert( |
| 7353 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7354 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7355 | "have different sizes."); |
| 7356 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7357 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7358 | "have different sizes."); |
| 7359 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7360 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7361 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7362 | instruction, root, /* unpoison_ref_before_marking= */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7363 | codegen_->AddSlowPath(slow_path); |
| 7364 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7365 | // Test the `Thread::Current()->pReadBarrierMarkReg ## root.reg()` entrypoint. |
| 7366 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7367 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(root.reg()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7368 | __ gs()->cmpl(Address::Absolute(entry_point_offset, /* no_rip= */ true), Immediate(0)); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7369 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7370 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7371 | __ Bind(slow_path->GetExitLabel()); |
| 7372 | } else { |
| 7373 | // GC root loaded through a slow path for read barriers other |
| 7374 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7375 | // /* GcRoot<mirror::Object>* */ root = address |
| 7376 | __ leaq(root_reg, address); |
| 7377 | if (fixup_label != nullptr) { |
| 7378 | __ Bind(fixup_label); |
| 7379 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7380 | // /* mirror::Object* */ root = root->Read() |
| 7381 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7382 | } |
| 7383 | } else { |
| 7384 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7385 | // /* GcRoot<mirror::Object> */ root = *address |
| 7386 | __ movl(root_reg, address); |
| 7387 | if (fixup_label != nullptr) { |
| 7388 | __ Bind(fixup_label); |
| 7389 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7390 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7391 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7392 | } |
| 7393 | } |
| 7394 | |
| 7395 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7396 | Location ref, |
| 7397 | CpuRegister obj, |
| 7398 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7399 | bool needs_null_check) { |
| 7400 | DCHECK(kEmitCompilerReadBarrier); |
| 7401 | DCHECK(kUseBakerReadBarrier); |
| 7402 | |
| 7403 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7404 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7405 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7406 | } |
| 7407 | |
| 7408 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7409 | Location ref, |
| 7410 | CpuRegister obj, |
| 7411 | uint32_t data_offset, |
| 7412 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7413 | bool needs_null_check) { |
| 7414 | DCHECK(kEmitCompilerReadBarrier); |
| 7415 | DCHECK(kUseBakerReadBarrier); |
| 7416 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7417 | static_assert( |
| 7418 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7419 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7420 | // /* HeapReference<Object> */ ref = |
| 7421 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7422 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7423 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7424 | } |
| 7425 | |
| 7426 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7427 | Location ref, |
| 7428 | CpuRegister obj, |
| 7429 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7430 | bool needs_null_check, |
| 7431 | bool always_update_field, |
| 7432 | CpuRegister* temp1, |
| 7433 | CpuRegister* temp2) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7434 | DCHECK(kEmitCompilerReadBarrier); |
| 7435 | DCHECK(kUseBakerReadBarrier); |
| 7436 | |
| 7437 | // In slow path based read barriers, the read barrier call is |
| 7438 | // inserted after the original load. However, in fast path based |
| 7439 | // Baker's read barriers, we need to perform the load of |
| 7440 | // mirror::Object::monitor_ *before* the original reference load. |
| 7441 | // This load-load ordering is required by the read barrier. |
| 7442 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7443 | // |
| 7444 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7445 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7446 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7447 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7448 | // if (is_gray) { |
| 7449 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7450 | // } |
| 7451 | // |
| 7452 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7453 | // slightly more complex as: |
| 7454 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7455 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7456 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 7457 | // 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] | 7458 | // - it performs additional checks that we do not do here for |
| 7459 | // performance reasons. |
| 7460 | |
| 7461 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7462 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7463 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7464 | // 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] | 7465 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7466 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7467 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7468 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7469 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7470 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7471 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7472 | // ref = ReadBarrier::Mark(ref); |
| 7473 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7474 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7475 | if (needs_null_check) { |
| 7476 | MaybeRecordImplicitNullCheck(instruction); |
| 7477 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7478 | |
| 7479 | // Load fence to prevent load-load reordering. |
| 7480 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 7481 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7482 | |
| 7483 | // The actual reference load. |
| 7484 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7485 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7486 | |
| 7487 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7488 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7489 | SlowPathCode* slow_path; |
| 7490 | if (always_update_field) { |
| 7491 | DCHECK(temp1 != nullptr); |
| 7492 | DCHECK(temp2 != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7493 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7494 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp1, *temp2); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7495 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7496 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7497 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7498 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7499 | AddSlowPath(slow_path); |
| 7500 | |
| 7501 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7502 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7503 | |
| 7504 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7505 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7506 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7507 | __ Bind(slow_path->GetExitLabel()); |
| 7508 | } |
| 7509 | |
| 7510 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7511 | Location out, |
| 7512 | Location ref, |
| 7513 | Location obj, |
| 7514 | uint32_t offset, |
| 7515 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7516 | DCHECK(kEmitCompilerReadBarrier); |
| 7517 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7518 | // Insert a slow path based read barrier *after* the reference load. |
| 7519 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7520 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7521 | // reference will be carried out by the runtime within the slow |
| 7522 | // path. |
| 7523 | // |
| 7524 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7525 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7526 | // not used by the artReadBarrierSlow entry point. |
| 7527 | // |
| 7528 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7529 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7530 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 7531 | AddSlowPath(slow_path); |
| 7532 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7533 | __ jmp(slow_path->GetEntryLabel()); |
| 7534 | __ Bind(slow_path->GetExitLabel()); |
| 7535 | } |
| 7536 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7537 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7538 | Location out, |
| 7539 | Location ref, |
| 7540 | Location obj, |
| 7541 | uint32_t offset, |
| 7542 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7543 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7544 | // Baker's read barriers shall be handled by the fast path |
| 7545 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 7546 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7547 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7548 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7549 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7550 | } else if (kPoisonHeapReferences) { |
| 7551 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 7552 | } |
| 7553 | } |
| 7554 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7555 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7556 | Location out, |
| 7557 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7558 | DCHECK(kEmitCompilerReadBarrier); |
| 7559 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7560 | // Insert a slow path based read barrier *after* the GC root load. |
| 7561 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7562 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7563 | // not need to do anything special for this here. |
| 7564 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7565 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7566 | AddSlowPath(slow_path); |
| 7567 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7568 | __ jmp(slow_path->GetEntryLabel()); |
| 7569 | __ Bind(slow_path->GetExitLabel()); |
| 7570 | } |
| 7571 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7572 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7573 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7574 | LOG(FATAL) << "Unreachable"; |
| 7575 | } |
| 7576 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7577 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7578 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7579 | LOG(FATAL) << "Unreachable"; |
| 7580 | } |
| 7581 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7582 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7583 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7584 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7585 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7586 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7587 | locations->AddTemp(Location::RequiresRegister()); |
| 7588 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7589 | } |
| 7590 | |
| 7591 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7592 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7593 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7594 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7595 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 7596 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 7597 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7598 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7599 | |
| 7600 | // Should we generate smaller inline compare/jumps? |
| 7601 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7602 | // Figure out the correct compare values and jump conditions. |
| 7603 | // Handle the first compare/branch as a special case because it might |
| 7604 | // jump to the default case. |
| 7605 | DCHECK_GT(num_entries, 2u); |
| 7606 | Condition first_condition; |
| 7607 | uint32_t index; |
| 7608 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7609 | if (lower_bound != 0) { |
| 7610 | first_condition = kLess; |
| 7611 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 7612 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7613 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 7614 | |
| 7615 | index = 1; |
| 7616 | } else { |
| 7617 | // Handle all the compare/jumps below. |
| 7618 | first_condition = kBelow; |
| 7619 | index = 0; |
| 7620 | } |
| 7621 | |
| 7622 | // Handle the rest of the compare/jumps. |
| 7623 | for (; index + 1 < num_entries; index += 2) { |
| 7624 | int32_t compare_to_value = lower_bound + index + 1; |
| 7625 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 7626 | // Jump to successors[index] if value < case_value[index]. |
| 7627 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7628 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7629 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7630 | } |
| 7631 | |
| 7632 | if (index != num_entries) { |
| 7633 | // There are an odd number of entries. Handle the last one. |
| 7634 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 7635 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7636 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 7637 | } |
| 7638 | |
| 7639 | // And the default for any other value. |
| 7640 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7641 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 7642 | } |
| 7643 | return; |
| 7644 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7645 | |
| 7646 | // Remove the bias, if needed. |
| 7647 | Register value_reg_out = value_reg_in.AsRegister(); |
| 7648 | if (lower_bound != 0) { |
| 7649 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 7650 | value_reg_out = temp_reg.AsRegister(); |
| 7651 | } |
| 7652 | CpuRegister value_reg(value_reg_out); |
| 7653 | |
| 7654 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7655 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7656 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7657 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7658 | // We are in the range of the table. |
| 7659 | // Load the address of the jump table in the constant area. |
| 7660 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7661 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7662 | // Load the (signed) offset from the jump table. |
| 7663 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 7664 | |
| 7665 | // Add the offset to the address of the table base. |
| 7666 | __ addq(temp_reg, base_reg); |
| 7667 | |
| 7668 | // And jump. |
| 7669 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7670 | } |
| 7671 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7672 | void LocationsBuilderX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7673 | ATTRIBUTE_UNUSED) { |
| 7674 | LOG(FATAL) << "Unreachable"; |
| 7675 | } |
| 7676 | |
| 7677 | void InstructionCodeGeneratorX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7678 | ATTRIBUTE_UNUSED) { |
| 7679 | LOG(FATAL) << "Unreachable"; |
| 7680 | } |
| 7681 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7682 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 7683 | if (value == 0) { |
| 7684 | __ xorl(dest, dest); |
| 7685 | } else { |
| 7686 | __ movl(dest, Immediate(value)); |
| 7687 | } |
| 7688 | } |
| 7689 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7690 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 7691 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7692 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7693 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 7694 | } else if (IsUint<32>(value)) { |
| 7695 | // 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] | 7696 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 7697 | } else { |
| 7698 | __ movq(dest, Immediate(value)); |
| 7699 | } |
| 7700 | } |
| 7701 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 7702 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 7703 | if (value == 0) { |
| 7704 | __ xorps(dest, dest); |
| 7705 | } else { |
| 7706 | __ movss(dest, LiteralInt32Address(value)); |
| 7707 | } |
| 7708 | } |
| 7709 | |
| 7710 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 7711 | if (value == 0) { |
| 7712 | __ xorpd(dest, dest); |
| 7713 | } else { |
| 7714 | __ movsd(dest, LiteralInt64Address(value)); |
| 7715 | } |
| 7716 | } |
| 7717 | |
| 7718 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 7719 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 7720 | } |
| 7721 | |
| 7722 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 7723 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 7724 | } |
| 7725 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7726 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 7727 | if (value == 0) { |
| 7728 | __ testl(dest, dest); |
| 7729 | } else { |
| 7730 | __ cmpl(dest, Immediate(value)); |
| 7731 | } |
| 7732 | } |
| 7733 | |
| 7734 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 7735 | if (IsInt<32>(value)) { |
| 7736 | if (value == 0) { |
| 7737 | __ testq(dest, dest); |
| 7738 | } else { |
| 7739 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 7740 | } |
| 7741 | } else { |
| 7742 | // Value won't fit in an int. |
| 7743 | __ cmpq(dest, LiteralInt64Address(value)); |
| 7744 | } |
| 7745 | } |
| 7746 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7747 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 7748 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7749 | GenerateIntCompare(lhs_reg, rhs); |
| 7750 | } |
| 7751 | |
| 7752 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7753 | if (rhs.IsConstant()) { |
| 7754 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7755 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7756 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7757 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7758 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7759 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7760 | } |
| 7761 | } |
| 7762 | |
| 7763 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 7764 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 7765 | if (rhs.IsConstant()) { |
| 7766 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 7767 | Compare64BitValue(lhs_reg, value); |
| 7768 | } else if (rhs.IsDoubleStackSlot()) { |
| 7769 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 7770 | } else { |
| 7771 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 7772 | } |
| 7773 | } |
| 7774 | |
| 7775 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 7776 | Location index, |
| 7777 | ScaleFactor scale, |
| 7778 | uint32_t data_offset) { |
| 7779 | return index.IsConstant() ? |
| 7780 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7781 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 7782 | } |
| 7783 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 7784 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 7785 | DCHECK(dest.IsDoubleStackSlot()); |
| 7786 | if (IsInt<32>(value)) { |
| 7787 | // Can move directly as an int32 constant. |
| 7788 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 7789 | Immediate(static_cast<int32_t>(value))); |
| 7790 | } else { |
| 7791 | Load64BitValue(CpuRegister(TMP), value); |
| 7792 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 7793 | } |
| 7794 | } |
| 7795 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7796 | /** |
| 7797 | * Class to handle late fixup of offsets into constant area. |
| 7798 | */ |
| 7799 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 7800 | public: |
| 7801 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 7802 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7803 | |
| 7804 | protected: |
| 7805 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7806 | |
| 7807 | CodeGeneratorX86_64* codegen_; |
| 7808 | |
| 7809 | private: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7810 | void Process(const MemoryRegion& region, int pos) override { |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7811 | // Patch the correct offset for the instruction. We use the address of the |
| 7812 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 7813 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7814 | int32_t relative_position = constant_offset - pos; |
| 7815 | |
| 7816 | // Patch in the right value. |
| 7817 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7818 | } |
| 7819 | |
| 7820 | // Location in constant area that the fixup refers to. |
| 7821 | size_t offset_into_constant_area_; |
| 7822 | }; |
| 7823 | |
| 7824 | /** |
| 7825 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7826 | * constant area. |
| 7827 | */ |
| 7828 | class JumpTableRIPFixup : public RIPFixup { |
| 7829 | public: |
| 7830 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 7831 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7832 | |
| 7833 | void CreateJumpTable() { |
| 7834 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7835 | |
| 7836 | // Ensure that the reference to the jump table has the correct offset. |
| 7837 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7838 | SetOffset(offset_in_constant_table); |
| 7839 | |
| 7840 | // Compute the offset from the start of the function to this jump table. |
| 7841 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7842 | |
| 7843 | // Populate the jump table with the correct values for the jump table. |
| 7844 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7845 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7846 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7847 | // The value that we want is the target offset - the position of the table. |
| 7848 | for (int32_t i = 0; i < num_entries; i++) { |
| 7849 | HBasicBlock* b = successors[i]; |
| 7850 | Label* l = codegen_->GetLabelOf(b); |
| 7851 | DCHECK(l->IsBound()); |
| 7852 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7853 | assembler->AppendInt32(offset_to_block); |
| 7854 | } |
| 7855 | } |
| 7856 | |
| 7857 | private: |
| 7858 | const HPackedSwitch* switch_instr_; |
| 7859 | }; |
| 7860 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7861 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7862 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7863 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7864 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7865 | // 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] | 7866 | assembler->Align(4, 0); |
| 7867 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7868 | |
| 7869 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7870 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7871 | jump_table->CreateJumpTable(); |
| 7872 | } |
| 7873 | |
| 7874 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7875 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7876 | } |
| 7877 | |
| 7878 | // And finish up. |
| 7879 | CodeGenerator::Finalize(allocator); |
| 7880 | } |
| 7881 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7882 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7883 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddDouble(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7884 | return Address::RIP(fixup); |
| 7885 | } |
| 7886 | |
| 7887 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7888 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddFloat(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7889 | return Address::RIP(fixup); |
| 7890 | } |
| 7891 | |
| 7892 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7893 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt32(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7894 | return Address::RIP(fixup); |
| 7895 | } |
| 7896 | |
| 7897 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7898 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt64(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7899 | return Address::RIP(fixup); |
| 7900 | } |
| 7901 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7902 | // TODO: trg as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7903 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7904 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7905 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7906 | return; |
| 7907 | } |
| 7908 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7909 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7910 | |
| 7911 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7912 | if (trg.Equals(return_loc)) { |
| 7913 | return; |
| 7914 | } |
| 7915 | |
| 7916 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7917 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7918 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7919 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7920 | } |
| 7921 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7922 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7923 | // Create a fixup to be used to create and address the jump table. |
| 7924 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7925 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7926 | |
| 7927 | // We have to populate the jump tables. |
| 7928 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7929 | return Address::RIP(table_fixup); |
| 7930 | } |
| 7931 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7932 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7933 | const Address& addr_high, |
| 7934 | int64_t v, |
| 7935 | HInstruction* instruction) { |
| 7936 | if (IsInt<32>(v)) { |
| 7937 | int32_t v_32 = v; |
| 7938 | __ movq(addr_low, Immediate(v_32)); |
| 7939 | MaybeRecordImplicitNullCheck(instruction); |
| 7940 | } else { |
| 7941 | // Didn't fit in a register. Do it in pieces. |
| 7942 | int32_t low_v = Low32Bits(v); |
| 7943 | int32_t high_v = High32Bits(v); |
| 7944 | __ movl(addr_low, Immediate(low_v)); |
| 7945 | MaybeRecordImplicitNullCheck(instruction); |
| 7946 | __ movl(addr_high, Immediate(high_v)); |
| 7947 | } |
| 7948 | } |
| 7949 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7950 | void CodeGeneratorX86_64::PatchJitRootUse(uint8_t* code, |
| 7951 | const uint8_t* roots_data, |
| 7952 | const PatchInfo<Label>& info, |
| 7953 | uint64_t index_in_table) const { |
| 7954 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7955 | uintptr_t address = |
| 7956 | 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] | 7957 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7958 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7959 | dchecked_integral_cast<uint32_t>(address); |
| 7960 | } |
| 7961 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7962 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7963 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7964 | 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] | 7965 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7966 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7967 | } |
| 7968 | |
| 7969 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7970 | 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] | 7971 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7972 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7973 | } |
| 7974 | } |
| 7975 | |
Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 7976 | bool LocationsBuilderX86_64::CpuHasAvxFeatureFlag() { |
| 7977 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 7978 | } |
| 7979 | |
| 7980 | bool LocationsBuilderX86_64::CpuHasAvx2FeatureFlag() { |
| 7981 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 7982 | } |
| 7983 | |
| 7984 | bool InstructionCodeGeneratorX86_64::CpuHasAvxFeatureFlag() { |
| 7985 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 7986 | } |
| 7987 | |
| 7988 | bool InstructionCodeGeneratorX86_64::CpuHasAvx2FeatureFlag() { |
| 7989 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 7990 | } |
| 7991 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7992 | #undef __ |
| 7993 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7994 | } // namespace x86_64 |
| 7995 | } // namespace art |