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 | |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 19 | #include "art_method-inl.h" |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 20 | #include "class_table.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 25 | #include "gc/space/image_space.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 26 | #include "heap_poisoning.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_x86_64.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 29 | #include "jit/profiling_info.h" |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 30 | #include "linker/linker_patch.h" |
Andreas Gampe | d490129 | 2017-05-30 18:41:34 -0700 | [diff] [blame] | 31 | #include "lock_word.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 32 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 33 | #include "mirror/class-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 34 | #include "mirror/object_reference.h" |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 35 | #include "scoped_thread_state_change-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 36 | #include "thread.h" |
| 37 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 38 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 39 | #include "utils/x86_64/assembler_x86_64.h" |
| 40 | #include "utils/x86_64/managed_register_x86_64.h" |
| 41 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 42 | namespace art { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 43 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 44 | template<class MirrorType> |
| 45 | class GcRoot; |
| 46 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 47 | namespace x86_64 { |
| 48 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 49 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 50 | static constexpr Register kMethodRegisterArgument = RDI; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 51 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 52 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 53 | // generates less code/data with a small num_entries. |
| 54 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 55 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 56 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 57 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 58 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 59 | static constexpr int kC2ConditionMask = 0x400; |
| 60 | |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 61 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 62 | // Custom calling convention: RAX serves as both input and output. |
| 63 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 64 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 65 | return caller_saves; |
| 66 | } |
| 67 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 68 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 69 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 70 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 71 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 72 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 74 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 76 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 77 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 78 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 79 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 80 | // Live registers will be restored in the catch block if caught. |
| 81 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 82 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 83 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 84 | instruction_, |
| 85 | instruction_->GetDexPc(), |
| 86 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 87 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 90 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 91 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 92 | const char* GetDescription() const override { return "NullCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 93 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 94 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 95 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 96 | }; |
| 97 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 98 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 100 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 102 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 103 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 105 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 106 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 109 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 110 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 111 | const char* GetDescription() const override { return "DivZeroCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 112 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 113 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 114 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 115 | }; |
| 116 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 117 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 118 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 119 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, DataType::Type type, bool is_div) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 120 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 121 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 122 | void EmitNativeCode(CodeGenerator* codegen) override { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 123 | __ Bind(GetEntryLabel()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 124 | if (type_ == DataType::Type::kInt32) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | if (is_div_) { |
| 126 | __ negl(cpu_reg_); |
| 127 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 128 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 131 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 132 | DCHECK_EQ(DataType::Type::kInt64, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 133 | if (is_div_) { |
| 134 | __ negq(cpu_reg_); |
| 135 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 136 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 137 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 138 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 139 | __ jmp(GetExitLabel()); |
| 140 | } |
| 141 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 142 | const char* GetDescription() const override { return "DivRemMinusOneSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 143 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 144 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 145 | const CpuRegister cpu_reg_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 146 | const DataType::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 147 | const bool is_div_; |
| 148 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 149 | }; |
| 150 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 151 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 152 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 153 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 154 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 155 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 156 | void EmitNativeCode(CodeGenerator* codegen) override { |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 157 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 158 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 159 | __ Bind(GetEntryLabel()); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 160 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 161 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 162 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 163 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 164 | if (successor_ == nullptr) { |
| 165 | __ jmp(GetReturnLabel()); |
| 166 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 167 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 168 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 171 | Label* GetReturnLabel() { |
| 172 | DCHECK(successor_ == nullptr); |
| 173 | return &return_label_; |
| 174 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 175 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 176 | HBasicBlock* GetSuccessor() const { |
| 177 | return successor_; |
| 178 | } |
| 179 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 180 | const char* GetDescription() const override { return "SuspendCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 181 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 182 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 183 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 184 | Label return_label_; |
| 185 | |
| 186 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 187 | }; |
| 188 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 189 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 190 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 191 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 192 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 193 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 194 | void EmitNativeCode(CodeGenerator* codegen) override { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 195 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 196 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 197 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 198 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 199 | // Live registers will be restored in the catch block if caught. |
| 200 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 201 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 202 | // Are we using an array length from memory? |
| 203 | HInstruction* array_length = instruction_->InputAt(1); |
| 204 | Location length_loc = locations->InAt(1); |
| 205 | InvokeRuntimeCallingConvention calling_convention; |
| 206 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 207 | // Load the array length into our temporary. |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 208 | HArrayLength* length = array_length->AsArrayLength(); |
Nicolas Geoffray | 003444a | 2017-10-17 10:58:42 +0100 | [diff] [blame] | 209 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 210 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 211 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 212 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 213 | // Check for conflicts with index. |
| 214 | if (length_loc.Equals(locations->InAt(0))) { |
| 215 | // We know we aren't using parameter 2. |
| 216 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 217 | } |
| 218 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 219 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 220 | __ shrl(length_loc.AsRegister<CpuRegister>(), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 221 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 222 | } |
| 223 | |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 224 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 225 | // move resolver. |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 226 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 227 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 228 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 229 | DataType::Type::kInt32, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 230 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 231 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 232 | DataType::Type::kInt32); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 233 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 234 | ? kQuickThrowStringBounds |
| 235 | : kQuickThrowArrayBounds; |
| 236 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 237 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 238 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 239 | } |
| 240 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 241 | bool IsFatal() const override { return true; } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 242 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 243 | const char* GetDescription() const override { return "BoundsCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 244 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 245 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 246 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 247 | }; |
| 248 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 249 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 250 | public: |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 251 | LoadClassSlowPathX86_64(HLoadClass* cls, HInstruction* at) |
| 252 | : SlowPathCode(at), cls_(cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 253 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 254 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 255 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 256 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 257 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 258 | LocationSummary* locations = instruction_->GetLocations(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 259 | Location out = locations->Out(); |
| 260 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 261 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 262 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| 263 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 264 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 265 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 266 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 267 | |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 268 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 269 | if (must_resolve_type) { |
| 270 | DCHECK(IsSameDexFile(cls_->GetDexFile(), x86_64_codegen->GetGraph()->GetDexFile())); |
| 271 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 272 | __ movl(CpuRegister(RAX), Immediate(type_index.index_)); |
Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 273 | x86_64_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 274 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 275 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 276 | } else { |
| 277 | DCHECK(must_do_clinit); |
| 278 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 279 | x86_64_codegen->Move(Location::RegisterLocation(RAX), source); |
| 280 | } |
| 281 | if (must_do_clinit) { |
| 282 | x86_64_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 283 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 284 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 285 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 286 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 287 | if (out.IsValid()) { |
| 288 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 289 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 292 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 293 | __ jmp(GetExitLabel()); |
| 294 | } |
| 295 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 296 | const char* GetDescription() const override { return "LoadClassSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 297 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 298 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 299 | // The class this slow path will load. |
| 300 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 301 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 302 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 303 | }; |
| 304 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 305 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
| 306 | public: |
| 307 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
| 308 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 309 | void EmitNativeCode(CodeGenerator* codegen) override { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 310 | LocationSummary* locations = instruction_->GetLocations(); |
| 311 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 312 | |
| 313 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 314 | __ Bind(GetEntryLabel()); |
| 315 | SaveLiveRegisters(codegen, locations); |
| 316 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 317 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 318 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 319 | __ movl(CpuRegister(RAX), Immediate(string_index.index_)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 320 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
| 321 | instruction_, |
| 322 | instruction_->GetDexPc(), |
| 323 | this); |
| 324 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 325 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 326 | RestoreLiveRegisters(codegen, locations); |
| 327 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 328 | __ jmp(GetExitLabel()); |
| 329 | } |
| 330 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 331 | const char* GetDescription() const override { return "LoadStringSlowPathX86_64"; } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 332 | |
| 333 | private: |
| 334 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 335 | }; |
| 336 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 337 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 338 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 339 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 340 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 341 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 342 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 343 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 344 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 345 | DCHECK(instruction_->IsCheckCast() |
| 346 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 347 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 348 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 349 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 350 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 351 | if (kPoisonHeapReferences && |
| 352 | instruction_->IsCheckCast() && |
| 353 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 354 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 355 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<CpuRegister>()); |
| 356 | } |
| 357 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 358 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 359 | SaveLiveRegisters(codegen, locations); |
| 360 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 361 | |
| 362 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 363 | // move resolver. |
| 364 | InvokeRuntimeCallingConvention calling_convention; |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 365 | codegen->EmitParallelMoves(locations->InAt(0), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 366 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 367 | DataType::Type::kReference, |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 368 | locations->InAt(1), |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 369 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 370 | DataType::Type::kReference); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 371 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 372 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 373 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 374 | } else { |
| 375 | DCHECK(instruction_->IsCheckCast()); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 376 | x86_64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 377 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 378 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 379 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 380 | if (!is_fatal_) { |
| 381 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 382 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 383 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 384 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 385 | RestoreLiveRegisters(codegen, locations); |
| 386 | __ jmp(GetExitLabel()); |
| 387 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 390 | const char* GetDescription() const override { return "TypeCheckSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 391 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 392 | bool IsFatal() const override { return is_fatal_; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 393 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 394 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 395 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 396 | |
| 397 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 398 | }; |
| 399 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 400 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 401 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 402 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 403 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 404 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 405 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 406 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 407 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 408 | LocationSummary* locations = instruction_->GetLocations(); |
| 409 | SaveLiveRegisters(codegen, locations); |
| 410 | InvokeRuntimeCallingConvention calling_convention; |
| 411 | x86_64_codegen->Load32BitValue( |
| 412 | CpuRegister(calling_convention.GetRegisterAt(0)), |
| 413 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 414 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 415 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 418 | const char* GetDescription() const override { return "DeoptimizationSlowPathX86_64"; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 419 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 420 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 421 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 422 | }; |
| 423 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 424 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 425 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 426 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 427 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 428 | void EmitNativeCode(CodeGenerator* codegen) override { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 429 | LocationSummary* locations = instruction_->GetLocations(); |
| 430 | __ Bind(GetEntryLabel()); |
| 431 | SaveLiveRegisters(codegen, locations); |
| 432 | |
| 433 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 434 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 435 | parallel_move.AddMove( |
| 436 | locations->InAt(0), |
| 437 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 438 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 439 | nullptr); |
| 440 | parallel_move.AddMove( |
| 441 | locations->InAt(1), |
| 442 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 443 | DataType::Type::kInt32, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 444 | nullptr); |
| 445 | parallel_move.AddMove( |
| 446 | locations->InAt(2), |
| 447 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 448 | DataType::Type::kReference, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 449 | nullptr); |
| 450 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 451 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 452 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 453 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 454 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 455 | RestoreLiveRegisters(codegen, locations); |
| 456 | __ jmp(GetExitLabel()); |
| 457 | } |
| 458 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 459 | const char* GetDescription() const override { return "ArraySetSlowPathX86_64"; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 460 | |
| 461 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 462 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 463 | }; |
| 464 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 465 | // Slow path marking an object reference `ref` during a read |
| 466 | // barrier. The field `obj.field` in the object `obj` holding this |
| 467 | // reference does not get updated by this slow path after marking (see |
| 468 | // ReadBarrierMarkAndUpdateFieldSlowPathX86_64 below for that). |
| 469 | // |
| 470 | // This means that after the execution of this slow path, `ref` will |
| 471 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 472 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 473 | // probably still be a from-space reference (unless it gets updated by |
| 474 | // another thread, or if another thread installed another object |
| 475 | // reference (different from `ref`) in `obj.field`). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 476 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 477 | public: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 478 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, |
| 479 | Location ref, |
| 480 | bool unpoison_ref_before_marking) |
| 481 | : SlowPathCode(instruction), |
| 482 | ref_(ref), |
| 483 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 484 | DCHECK(kEmitCompilerReadBarrier); |
| 485 | } |
| 486 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 487 | const char* GetDescription() const override { return "ReadBarrierMarkSlowPathX86_64"; } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 488 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 489 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 490 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 491 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 492 | Register ref_reg = ref_cpu_reg.AsRegister(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 493 | DCHECK(locations->CanCall()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 494 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 495 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 496 | instruction_->IsStaticFieldGet() || |
| 497 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 498 | instruction_->IsArraySet() || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 499 | instruction_->IsLoadClass() || |
| 500 | instruction_->IsLoadString() || |
| 501 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 502 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 503 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 504 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 505 | << "Unexpected instruction in read barrier marking slow path: " |
| 506 | << instruction_->DebugName(); |
| 507 | |
| 508 | __ Bind(GetEntryLabel()); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 509 | if (unpoison_ref_before_marking_) { |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 510 | // Object* ref = ref_addr->AsMirrorPtr() |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 511 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 512 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 513 | // No need to save live registers; it's taken care of by the |
| 514 | // entrypoint. Also, there is no need to update the stack mask, |
| 515 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 516 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 517 | DCHECK_NE(ref_reg, RSP); |
| 518 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 519 | // "Compact" slow path, saving two moves. |
| 520 | // |
| 521 | // Instead of using the standard runtime calling convention (input |
| 522 | // and output in R0): |
| 523 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 524 | // RDI <- ref |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 525 | // RAX <- ReadBarrierMark(RDI) |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 526 | // ref <- RAX |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 527 | // |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 528 | // we just use rX (the register containing `ref`) as input and output |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 529 | // of a dedicated entrypoint: |
| 530 | // |
| 531 | // rX <- ReadBarrierMarkRegX(rX) |
| 532 | // |
| 533 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 534 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 535 | // This runtime call does not require a stack map. |
| 536 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 537 | __ jmp(GetExitLabel()); |
| 538 | } |
| 539 | |
| 540 | private: |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 541 | // The location (register) of the marked object reference. |
| 542 | const Location ref_; |
| 543 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 544 | const bool unpoison_ref_before_marking_; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 545 | |
| 546 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 547 | }; |
| 548 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 549 | // Slow path marking an object reference `ref` during a read barrier, |
| 550 | // and if needed, atomically updating the field `obj.field` in the |
| 551 | // object `obj` holding this reference after marking (contrary to |
| 552 | // ReadBarrierMarkSlowPathX86_64 above, which never tries to update |
| 553 | // `obj.field`). |
| 554 | // |
| 555 | // This means that after the execution of this slow path, both `ref` |
| 556 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 557 | // hold the same to-space reference (unless another thread installed |
| 558 | // another object reference (different from `ref`) in `obj.field`). |
| 559 | class ReadBarrierMarkAndUpdateFieldSlowPathX86_64 : public SlowPathCode { |
| 560 | public: |
| 561 | ReadBarrierMarkAndUpdateFieldSlowPathX86_64(HInstruction* instruction, |
| 562 | Location ref, |
| 563 | CpuRegister obj, |
| 564 | const Address& field_addr, |
| 565 | bool unpoison_ref_before_marking, |
| 566 | CpuRegister temp1, |
| 567 | CpuRegister temp2) |
| 568 | : SlowPathCode(instruction), |
| 569 | ref_(ref), |
| 570 | obj_(obj), |
| 571 | field_addr_(field_addr), |
| 572 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 573 | temp1_(temp1), |
| 574 | temp2_(temp2) { |
| 575 | DCHECK(kEmitCompilerReadBarrier); |
| 576 | } |
| 577 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 578 | const char* GetDescription() const override { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 579 | return "ReadBarrierMarkAndUpdateFieldSlowPathX86_64"; |
| 580 | } |
| 581 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 582 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 583 | LocationSummary* locations = instruction_->GetLocations(); |
| 584 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 585 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| 586 | DCHECK(locations->CanCall()); |
| 587 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 588 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 589 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 590 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 591 | << instruction_->DebugName(); |
| 592 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 593 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 594 | |
| 595 | __ Bind(GetEntryLabel()); |
| 596 | if (unpoison_ref_before_marking_) { |
| 597 | // Object* ref = ref_addr->AsMirrorPtr() |
| 598 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| 599 | } |
| 600 | |
| 601 | // Save the old (unpoisoned) reference. |
| 602 | __ movl(temp1_, ref_cpu_reg); |
| 603 | |
| 604 | // No need to save live registers; it's taken care of by the |
| 605 | // entrypoint. Also, there is no need to update the stack mask, |
| 606 | // as this runtime call will not trigger a garbage collection. |
| 607 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 608 | DCHECK_NE(ref_reg, RSP); |
| 609 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 610 | // "Compact" slow path, saving two moves. |
| 611 | // |
| 612 | // Instead of using the standard runtime calling convention (input |
| 613 | // and output in R0): |
| 614 | // |
| 615 | // RDI <- ref |
| 616 | // RAX <- ReadBarrierMark(RDI) |
| 617 | // ref <- RAX |
| 618 | // |
| 619 | // we just use rX (the register containing `ref`) as input and output |
| 620 | // of a dedicated entrypoint: |
| 621 | // |
| 622 | // rX <- ReadBarrierMarkRegX(rX) |
| 623 | // |
| 624 | int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 625 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 626 | // This runtime call does not require a stack map. |
| 627 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 628 | |
| 629 | // If the new reference is different from the old reference, |
| 630 | // update the field in the holder (`*field_addr`). |
| 631 | // |
| 632 | // Note that this field could also hold a different object, if |
| 633 | // another thread had concurrently changed it. In that case, the |
| 634 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 635 | // operation below would abort the CAS, leaving the field as-is. |
| 636 | NearLabel done; |
| 637 | __ cmpl(temp1_, ref_cpu_reg); |
| 638 | __ j(kEqual, &done); |
| 639 | |
| 640 | // Update the the holder's field atomically. This may fail if |
| 641 | // mutator updates before us, but it's OK. This is achived |
| 642 | // using a strong compare-and-set (CAS) operation with relaxed |
| 643 | // memory synchronization ordering, where the expected value is |
| 644 | // the old reference and the desired value is the new reference. |
| 645 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 646 | // instruction, which requires the expected value (the old |
| 647 | // reference) to be in EAX. Save RAX beforehand, and move the |
| 648 | // expected value (stored in `temp1_`) into EAX. |
| 649 | __ movq(temp2_, CpuRegister(RAX)); |
| 650 | __ movl(CpuRegister(RAX), temp1_); |
| 651 | |
| 652 | // Convenience aliases. |
| 653 | CpuRegister base = obj_; |
| 654 | CpuRegister expected = CpuRegister(RAX); |
| 655 | CpuRegister value = ref_cpu_reg; |
| 656 | |
| 657 | bool base_equals_value = (base.AsRegister() == value.AsRegister()); |
| 658 | Register value_reg = ref_reg; |
| 659 | if (kPoisonHeapReferences) { |
| 660 | if (base_equals_value) { |
| 661 | // If `base` and `value` are the same register location, move |
| 662 | // `value_reg` to a temporary register. This way, poisoning |
| 663 | // `value_reg` won't invalidate `base`. |
| 664 | value_reg = temp1_.AsRegister(); |
| 665 | __ movl(CpuRegister(value_reg), base); |
| 666 | } |
| 667 | |
| 668 | // Check that the register allocator did not assign the location |
| 669 | // of `expected` (RAX) to `value` nor to `base`, so that heap |
| 670 | // poisoning (when enabled) works as intended below. |
| 671 | // - If `value` were equal to `expected`, both references would |
| 672 | // be poisoned twice, meaning they would not be poisoned at |
| 673 | // all, as heap poisoning uses address negation. |
| 674 | // - If `base` were equal to `expected`, poisoning `expected` |
| 675 | // would invalidate `base`. |
| 676 | DCHECK_NE(value_reg, expected.AsRegister()); |
| 677 | DCHECK_NE(base.AsRegister(), expected.AsRegister()); |
| 678 | |
| 679 | __ PoisonHeapReference(expected); |
| 680 | __ PoisonHeapReference(CpuRegister(value_reg)); |
| 681 | } |
| 682 | |
| 683 | __ LockCmpxchgl(field_addr_, CpuRegister(value_reg)); |
| 684 | |
| 685 | // If heap poisoning is enabled, we need to unpoison the values |
| 686 | // that were poisoned earlier. |
| 687 | if (kPoisonHeapReferences) { |
| 688 | if (base_equals_value) { |
| 689 | // `value_reg` has been moved to a temporary register, no need |
| 690 | // to unpoison it. |
| 691 | } else { |
| 692 | __ UnpoisonHeapReference(CpuRegister(value_reg)); |
| 693 | } |
| 694 | // No need to unpoison `expected` (RAX), as it is be overwritten below. |
| 695 | } |
| 696 | |
| 697 | // Restore RAX. |
| 698 | __ movq(CpuRegister(RAX), temp2_); |
| 699 | |
| 700 | __ Bind(&done); |
| 701 | __ jmp(GetExitLabel()); |
| 702 | } |
| 703 | |
| 704 | private: |
| 705 | // The location (register) of the marked object reference. |
| 706 | const Location ref_; |
| 707 | // The register containing the object holding the marked object reference field. |
| 708 | const CpuRegister obj_; |
| 709 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 710 | const Address field_addr_; |
| 711 | |
| 712 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 713 | const bool unpoison_ref_before_marking_; |
| 714 | |
| 715 | const CpuRegister temp1_; |
| 716 | const CpuRegister temp2_; |
| 717 | |
| 718 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86_64); |
| 719 | }; |
| 720 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 721 | // Slow path generating a read barrier for a heap reference. |
| 722 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 723 | public: |
| 724 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 725 | Location out, |
| 726 | Location ref, |
| 727 | Location obj, |
| 728 | uint32_t offset, |
| 729 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 730 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 731 | out_(out), |
| 732 | ref_(ref), |
| 733 | obj_(obj), |
| 734 | offset_(offset), |
| 735 | index_(index) { |
| 736 | DCHECK(kEmitCompilerReadBarrier); |
| 737 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 738 | // object has been overwritten by (or after) the heap object |
| 739 | // reference load to be instrumented, e.g.: |
| 740 | // |
| 741 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 742 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 743 | // |
| 744 | // In that case, we have lost the information about the original |
| 745 | // object, and the emitted read barrier cannot work properly. |
| 746 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 747 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 748 | } |
| 749 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 750 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 751 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 752 | LocationSummary* locations = instruction_->GetLocations(); |
| 753 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 754 | DCHECK(locations->CanCall()); |
| 755 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 756 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 757 | instruction_->IsStaticFieldGet() || |
| 758 | instruction_->IsArrayGet() || |
| 759 | instruction_->IsInstanceOf() || |
| 760 | instruction_->IsCheckCast() || |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 761 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 762 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 763 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 764 | |
| 765 | __ Bind(GetEntryLabel()); |
| 766 | SaveLiveRegisters(codegen, locations); |
| 767 | |
| 768 | // We may have to change the index's value, but as `index_` is a |
| 769 | // constant member (like other "inputs" of this slow path), |
| 770 | // introduce a copy of it, `index`. |
| 771 | Location index = index_; |
| 772 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 773 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 774 | if (instruction_->IsArrayGet()) { |
| 775 | // Compute real offset and store it in index_. |
| 776 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 777 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 778 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 779 | // We are about to change the value of `index_reg` (see the |
| 780 | // calls to art::x86_64::X86_64Assembler::shll and |
| 781 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 782 | // has not been saved by the previous call to |
| 783 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 784 | // callee-save register -- |
| 785 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 786 | // callee-save registers, as it has been designed with the |
| 787 | // assumption that callee-save registers are supposed to be |
| 788 | // handled by the called function. So, as a callee-save |
| 789 | // register, `index_reg` _would_ eventually be saved onto |
| 790 | // the stack, but it would be too late: we would have |
| 791 | // changed its value earlier. Therefore, we manually save |
| 792 | // it here into another freely available register, |
| 793 | // `free_reg`, chosen of course among the caller-save |
| 794 | // registers (as a callee-save `free_reg` register would |
| 795 | // exhibit the same problem). |
| 796 | // |
| 797 | // Note we could have requested a temporary register from |
| 798 | // the register allocator instead; but we prefer not to, as |
| 799 | // this is a slow path, and we know we can find a |
| 800 | // caller-save register that is available. |
| 801 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 802 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 803 | index_reg = free_reg; |
| 804 | index = Location::RegisterLocation(index_reg); |
| 805 | } else { |
| 806 | // The initial register stored in `index_` has already been |
| 807 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 808 | // (as it is not a callee-save register), so we can freely |
| 809 | // use it. |
| 810 | } |
| 811 | // Shifting the index value contained in `index_reg` by the |
| 812 | // scale factor (2) cannot overflow in practice, as the |
| 813 | // runtime is unable to allocate object arrays with a size |
| 814 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 815 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 816 | static_assert( |
| 817 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 818 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 819 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 820 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 821 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 822 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 823 | // (as in the case of ArrayGet), as it is actually an offset |
| 824 | // to an object field within an object. |
| 825 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 826 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 827 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 828 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 829 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 830 | DCHECK_EQ(offset_, 0U); |
| 831 | DCHECK(index_.IsRegister()); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | // We're moving two or three locations to locations that could |
| 836 | // overlap, so we need a parallel move resolver. |
| 837 | InvokeRuntimeCallingConvention calling_convention; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 838 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 839 | parallel_move.AddMove(ref_, |
| 840 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 841 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 842 | nullptr); |
| 843 | parallel_move.AddMove(obj_, |
| 844 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 845 | DataType::Type::kReference, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 846 | nullptr); |
| 847 | if (index.IsValid()) { |
| 848 | parallel_move.AddMove(index, |
| 849 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 850 | DataType::Type::kInt32, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 851 | nullptr); |
| 852 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 853 | } else { |
| 854 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 855 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 856 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 857 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 858 | instruction_, |
| 859 | instruction_->GetDexPc(), |
| 860 | this); |
| 861 | CheckEntrypointTypes< |
| 862 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 863 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 864 | |
| 865 | RestoreLiveRegisters(codegen, locations); |
| 866 | __ jmp(GetExitLabel()); |
| 867 | } |
| 868 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 869 | const char* GetDescription() const override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 870 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 871 | } |
| 872 | |
| 873 | private: |
| 874 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 875 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 876 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 877 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 878 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 879 | return static_cast<CpuRegister>(i); |
| 880 | } |
| 881 | } |
| 882 | // We shall never fail to find a free caller-save register, as |
| 883 | // there are more than two core caller-save registers on x86-64 |
| 884 | // (meaning it is possible to find one which is different from |
| 885 | // `ref` and `obj`). |
| 886 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 887 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 888 | UNREACHABLE(); |
| 889 | } |
| 890 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 891 | const Location out_; |
| 892 | const Location ref_; |
| 893 | const Location obj_; |
| 894 | const uint32_t offset_; |
| 895 | // An additional location containing an index to an array. |
| 896 | // Only used for HArrayGet and the UnsafeGetObject & |
| 897 | // UnsafeGetObjectVolatile intrinsics. |
| 898 | const Location index_; |
| 899 | |
| 900 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 901 | }; |
| 902 | |
| 903 | // Slow path generating a read barrier for a GC root. |
| 904 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 905 | public: |
| 906 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 907 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 908 | DCHECK(kEmitCompilerReadBarrier); |
| 909 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 910 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 911 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 912 | LocationSummary* locations = instruction_->GetLocations(); |
| 913 | DCHECK(locations->CanCall()); |
| 914 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 915 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 916 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 917 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 918 | |
| 919 | __ Bind(GetEntryLabel()); |
| 920 | SaveLiveRegisters(codegen, locations); |
| 921 | |
| 922 | InvokeRuntimeCallingConvention calling_convention; |
| 923 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 924 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 925 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 926 | instruction_, |
| 927 | instruction_->GetDexPc(), |
| 928 | this); |
| 929 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 930 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 931 | |
| 932 | RestoreLiveRegisters(codegen, locations); |
| 933 | __ jmp(GetExitLabel()); |
| 934 | } |
| 935 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 936 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathX86_64"; } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 937 | |
| 938 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 939 | const Location out_; |
| 940 | const Location root_; |
| 941 | |
| 942 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 943 | }; |
| 944 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 945 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 946 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 947 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 948 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 949 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 950 | switch (cond) { |
| 951 | case kCondEQ: return kEqual; |
| 952 | case kCondNE: return kNotEqual; |
| 953 | case kCondLT: return kLess; |
| 954 | case kCondLE: return kLessEqual; |
| 955 | case kCondGT: return kGreater; |
| 956 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 957 | case kCondB: return kBelow; |
| 958 | case kCondBE: return kBelowEqual; |
| 959 | case kCondA: return kAbove; |
| 960 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 961 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 962 | LOG(FATAL) << "Unreachable"; |
| 963 | UNREACHABLE(); |
| 964 | } |
| 965 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 966 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 967 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 968 | switch (cond) { |
| 969 | case kCondEQ: return kEqual; |
| 970 | case kCondNE: return kNotEqual; |
| 971 | case kCondLT: return kBelow; |
| 972 | case kCondLE: return kBelowEqual; |
| 973 | case kCondGT: return kAbove; |
| 974 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 975 | default: break; // should not happen |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 976 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 977 | LOG(FATAL) << "Unreachable"; |
| 978 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 981 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 982 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 983 | ArtMethod* method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 984 | return desired_dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 985 | } |
| 986 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 987 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall( |
| 988 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 989 | // All registers are assumed to be correctly set up. |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 990 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 991 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 992 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 993 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 994 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 995 | uint32_t offset = |
| 996 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 997 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip= */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 998 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 999 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1000 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1001 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1002 | break; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1003 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 1004 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1005 | __ leal(temp.AsRegister<CpuRegister>(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1006 | Address::Absolute(kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1007 | RecordBootImageMethodPatch(invoke); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1008 | break; |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1009 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 1010 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 1011 | __ movl(temp.AsRegister<CpuRegister>(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1012 | Address::Absolute(kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1013 | RecordBootImageRelRoPatch(GetBootImageOffset(invoke)); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1014 | break; |
| 1015 | } |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1016 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1017 | __ movq(temp.AsRegister<CpuRegister>(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1018 | Address::Absolute(kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1019 | RecordMethodBssEntryPatch(invoke); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 1020 | // No need for memory fence, thanks to the x86-64 memory model. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1021 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1022 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 1023 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 1024 | Load64BitValue(temp.AsRegister<CpuRegister>(), invoke->GetMethodAddress()); |
| 1025 | break; |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1026 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 1027 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 1028 | return; // No code pointer retrieval; the runtime performs the call directly. |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1029 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | switch (invoke->GetCodePtrLocation()) { |
| 1033 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 1034 | __ call(&frame_entry_label_); |
| 1035 | break; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1036 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 1037 | // (callee_method + offset_of_quick_compiled_code)() |
| 1038 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1039 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1040 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1041 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1042 | } |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1043 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1044 | |
| 1045 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1048 | void CodeGeneratorX86_64::GenerateVirtualCall( |
| 1049 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1050 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1051 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1052 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1053 | |
| 1054 | // Use the calling convention instead of the location of the receiver, as |
| 1055 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1056 | // slow path, the arguments have been moved to the right place, so here we are |
| 1057 | // guaranteed that the receiver is the first register of the calling convention. |
| 1058 | InvokeDexCallingConvention calling_convention; |
| 1059 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1060 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1061 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1062 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1063 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1064 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1065 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1066 | // emit a read barrier for the previous class reference load. |
| 1067 | // However this is not required in practice, as this is an |
| 1068 | // intermediate/temporary reference and because the current |
| 1069 | // concurrent copying collector keeps the from-space memory |
| 1070 | // intact/accessible until the end of the marking phase (the |
| 1071 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1072 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 1073 | |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame^] | 1074 | MaybeGenerateInlineCacheCheck(invoke, temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 1075 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1076 | // temp = temp->GetMethodAt(method_offset); |
| 1077 | __ movq(temp, Address(temp, method_offset)); |
| 1078 | // call temp->GetEntryPoint(); |
| 1079 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1080 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1081 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1084 | void CodeGeneratorX86_64::RecordBootImageIntrinsicPatch(uint32_t intrinsic_data) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1085 | boot_image_other_patches_.emplace_back(/* target_dex_file= */ nullptr, intrinsic_data); |
| 1086 | __ Bind(&boot_image_other_patches_.back().label); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1087 | } |
| 1088 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1089 | void CodeGeneratorX86_64::RecordBootImageRelRoPatch(uint32_t boot_image_offset) { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1090 | boot_image_other_patches_.emplace_back(/* target_dex_file= */ nullptr, boot_image_offset); |
| 1091 | __ Bind(&boot_image_other_patches_.back().label); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1094 | void CodeGeneratorX86_64::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 1095 | boot_image_method_patches_.emplace_back( |
| 1096 | invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1097 | __ Bind(&boot_image_method_patches_.back().label); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1100 | void CodeGeneratorX86_64::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { |
| 1101 | method_bss_entry_patches_.emplace_back(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 1102 | __ Bind(&method_bss_entry_patches_.back().label); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1103 | } |
| 1104 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1105 | void CodeGeneratorX86_64::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 1106 | boot_image_type_patches_.emplace_back( |
| 1107 | &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1108 | __ Bind(&boot_image_type_patches_.back().label); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1109 | } |
| 1110 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1111 | Label* CodeGeneratorX86_64::NewTypeBssEntryPatch(HLoadClass* load_class) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1112 | type_bss_entry_patches_.emplace_back( |
| 1113 | &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1114 | return &type_bss_entry_patches_.back().label; |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1117 | void CodeGeneratorX86_64::RecordBootImageStringPatch(HLoadString* load_string) { |
| 1118 | boot_image_string_patches_.emplace_back( |
| 1119 | &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 1120 | __ Bind(&boot_image_string_patches_.back().label); |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1123 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1124 | string_bss_entry_patches_.emplace_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1125 | &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1126 | return &string_bss_entry_patches_.back().label; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1129 | void CodeGeneratorX86_64::LoadBootImageAddress(CpuRegister reg, uint32_t boot_image_reference) { |
| 1130 | if (GetCompilerOptions().IsBootImage()) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1131 | __ leal(reg, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1132 | RecordBootImageIntrinsicPatch(boot_image_reference); |
Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 1133 | } else if (GetCompilerOptions().GetCompilePic()) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1134 | __ movl(reg, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1135 | RecordBootImageRelRoPatch(boot_image_reference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1136 | } else { |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 1137 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1138 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1139 | DCHECK(!heap->GetBootImageSpaces().empty()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1140 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1141 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 1142 | } |
| 1143 | } |
| 1144 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1145 | void CodeGeneratorX86_64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 1146 | uint32_t boot_image_offset) { |
| 1147 | DCHECK(invoke->IsStatic()); |
| 1148 | InvokeRuntimeCallingConvention calling_convention; |
| 1149 | CpuRegister argument = CpuRegister(calling_convention.GetRegisterAt(0)); |
| 1150 | if (GetCompilerOptions().IsBootImage()) { |
| 1151 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 1152 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 1153 | __ leal(argument, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1154 | Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1155 | MethodReference target_method = invoke->GetTargetMethod(); |
| 1156 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 1157 | boot_image_type_patches_.emplace_back(target_method.dex_file, type_idx.index_); |
| 1158 | __ Bind(&boot_image_type_patches_.back().label); |
| 1159 | } else { |
| 1160 | LoadBootImageAddress(argument, boot_image_offset); |
| 1161 | } |
| 1162 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 1163 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 1164 | } |
| 1165 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1166 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 1167 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 1168 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 1169 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1170 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1171 | inline void CodeGeneratorX86_64::EmitPcRelativeLinkerPatches( |
| 1172 | const ArenaDeque<PatchInfo<Label>>& infos, |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1173 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1174 | for (const PatchInfo<Label>& info : infos) { |
| 1175 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1176 | linker_patches->push_back( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1177 | 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] | 1178 | } |
| 1179 | } |
| 1180 | |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1181 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 1182 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 1183 | const DexFile* target_dex_file, |
| 1184 | uint32_t pc_insn_offset, |
| 1185 | uint32_t boot_image_offset) { |
| 1186 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 1187 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1190 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1191 | DCHECK(linker_patches->empty()); |
| 1192 | size_t size = |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1193 | boot_image_method_patches_.size() + |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1194 | method_bss_entry_patches_.size() + |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1195 | boot_image_type_patches_.size() + |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1196 | type_bss_entry_patches_.size() + |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1197 | boot_image_string_patches_.size() + |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1198 | string_bss_entry_patches_.size() + |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1199 | boot_image_other_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1200 | linker_patches->reserve(size); |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 1201 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1202 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1203 | boot_image_method_patches_, linker_patches); |
| 1204 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1205 | boot_image_type_patches_, linker_patches); |
| 1206 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1207 | boot_image_string_patches_, linker_patches); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1208 | } else { |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1209 | DCHECK(boot_image_method_patches_.empty()); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1210 | DCHECK(boot_image_type_patches_.empty()); |
| 1211 | DCHECK(boot_image_string_patches_.empty()); |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1212 | } |
| 1213 | if (GetCompilerOptions().IsBootImage()) { |
| 1214 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 1215 | boot_image_other_patches_, linker_patches); |
| 1216 | } else { |
| 1217 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 1218 | boot_image_other_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1219 | } |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1220 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1221 | method_bss_entry_patches_, linker_patches); |
| 1222 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1223 | type_bss_entry_patches_, linker_patches); |
| 1224 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1225 | string_bss_entry_patches_, linker_patches); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1226 | DCHECK_EQ(size, linker_patches->size()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1229 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1230 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1234 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1235 | } |
| 1236 | |
Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1237 | const X86_64InstructionSetFeatures& CodeGeneratorX86_64::GetInstructionSetFeatures() const { |
| 1238 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86_64InstructionSetFeatures(); |
| 1239 | } |
| 1240 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1241 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1242 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1243 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1244 | } |
| 1245 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1246 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1247 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1248 | return kX86_64WordSize; |
| 1249 | } |
| 1250 | |
| 1251 | 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] | 1252 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1253 | __ movups(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1254 | } else { |
| 1255 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1256 | } |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1257 | return GetSlowPathFPWidth(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | 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] | 1261 | if (GetGraph()->HasSIMD()) { |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1262 | __ movups(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1263 | } else { |
| 1264 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1265 | } |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1266 | return GetSlowPathFPWidth(); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1267 | } |
| 1268 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1269 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1270 | HInstruction* instruction, |
| 1271 | uint32_t dex_pc, |
| 1272 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1273 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1274 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1275 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1276 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1277 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1278 | } |
| 1279 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1280 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1281 | HInstruction* instruction, |
| 1282 | SlowPathCode* slow_path) { |
| 1283 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1284 | GenerateInvokeRuntime(entry_point_offset); |
| 1285 | } |
| 1286 | |
| 1287 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1288 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip= */ true)); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1289 | } |
| 1290 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1291 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1292 | // Use a fake return address register to mimic Quick. |
| 1293 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1294 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1295 | const CompilerOptions& compiler_options, |
| 1296 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1297 | : CodeGenerator(graph, |
| 1298 | kNumberOfCpuRegisters, |
| 1299 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1300 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1301 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1302 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1303 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1304 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1305 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1306 | compiler_options, |
| 1307 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1308 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1309 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1310 | instruction_visitor_(graph, this), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1311 | move_resolver_(graph->GetAllocator(), this), |
| 1312 | assembler_(graph->GetAllocator()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1313 | constant_area_start_(0), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1314 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1315 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1316 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1317 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1318 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1319 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1320 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1321 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1322 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1323 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1324 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1325 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1326 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1327 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1328 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1329 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1330 | assembler_(codegen->GetAssembler()), |
| 1331 | codegen_(codegen) {} |
| 1332 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1333 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1334 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1335 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1336 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1337 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1338 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1339 | } |
| 1340 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1341 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1342 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1343 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1344 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1345 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1346 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1349 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1350 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1351 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1352 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1353 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1354 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1355 | |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1356 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
Mathieu Chartier | 7f8678e | 2019-08-30 16:22:28 -0700 | [diff] [blame] | 1357 | NearLabel overflow; |
| 1358 | __ cmpw(Address(CpuRegister(kMethodRegisterArgument), |
| 1359 | ArtMethod::HotnessCountOffset().Int32Value()), |
| 1360 | Immediate(ArtMethod::MaxCounter())); |
| 1361 | __ j(kEqual, &overflow); |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1362 | __ addw(Address(CpuRegister(kMethodRegisterArgument), |
| 1363 | ArtMethod::HotnessCountOffset().Int32Value()), |
| 1364 | Immediate(1)); |
Mathieu Chartier | 7f8678e | 2019-08-30 16:22:28 -0700 | [diff] [blame] | 1365 | __ Bind(&overflow); |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1368 | if (!skip_overflow_check) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1369 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86_64); |
| 1370 | __ testq(CpuRegister(RAX), Address(CpuRegister(RSP), -static_cast<int32_t>(reserved_bytes))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1371 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1372 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1373 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1374 | if (HasEmptyFrame()) { |
| 1375 | return; |
| 1376 | } |
| 1377 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1378 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1379 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1380 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1381 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1382 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1383 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1384 | } |
| 1385 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1386 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1387 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1388 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1389 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1390 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1391 | size_t xmm_spill_slot_size = GetCalleePreservedFPWidth(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1392 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1393 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1394 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1395 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1396 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1397 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1398 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1399 | } |
| 1400 | |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1401 | // Save the current method if we need it. Note that we do not |
| 1402 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1403 | // in the SSA graph. |
| 1404 | if (RequiresCurrentMethod()) { |
| 1405 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1406 | CpuRegister(kMethodRegisterArgument)); |
| 1407 | } |
Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1408 | |
| 1409 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1410 | // Initialize should_deoptimize flag to 0. |
| 1411 | __ movl(Address(CpuRegister(RSP), GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1412 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1416 | __ cfi().RememberState(); |
| 1417 | if (!HasEmptyFrame()) { |
| 1418 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 1419 | size_t xmm_spill_slot_size = GetCalleePreservedFPWidth(); |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1420 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1421 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1422 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1423 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1424 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1429 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1430 | __ cfi().AdjustCFAOffset(-adjust); |
| 1431 | |
| 1432 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1433 | Register reg = kCoreCalleeSaves[i]; |
| 1434 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1435 | __ popq(CpuRegister(reg)); |
| 1436 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1437 | __ cfi().Restore(DWARFReg(reg)); |
| 1438 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1439 | } |
| 1440 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1441 | __ ret(); |
| 1442 | __ cfi().RestoreState(); |
| 1443 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1444 | } |
| 1445 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1446 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1447 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1448 | } |
| 1449 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1450 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1451 | if (source.Equals(destination)) { |
| 1452 | return; |
| 1453 | } |
| 1454 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1455 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1456 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1457 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1458 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1459 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1460 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1461 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1462 | } else if (source.IsConstant()) { |
| 1463 | HConstant* constant = source.GetConstant(); |
| 1464 | if (constant->IsLongConstant()) { |
| 1465 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1466 | } else { |
| 1467 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1468 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1469 | } else { |
| 1470 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1471 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1472 | } |
| 1473 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1474 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1475 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1476 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1477 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1478 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1479 | } else if (source.IsConstant()) { |
| 1480 | HConstant* constant = source.GetConstant(); |
| 1481 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1482 | if (constant->IsFloatConstant()) { |
| 1483 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1484 | } else { |
| 1485 | Load64BitValue(dest, value); |
| 1486 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1487 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1488 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1489 | } else { |
| 1490 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1491 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1492 | } |
| 1493 | } else if (destination.IsStackSlot()) { |
| 1494 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1495 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1496 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1497 | } else if (source.IsFpuRegister()) { |
| 1498 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1499 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1500 | } else if (source.IsConstant()) { |
| 1501 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1502 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1503 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1504 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1505 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1506 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1507 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1508 | } |
| 1509 | } else { |
| 1510 | DCHECK(destination.IsDoubleStackSlot()); |
| 1511 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1512 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1513 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1514 | } else if (source.IsFpuRegister()) { |
| 1515 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1516 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1517 | } else if (source.IsConstant()) { |
| 1518 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1519 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1520 | int64_t value = GetInt64ValueOf(constant); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1521 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1522 | } else { |
| 1523 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1524 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1525 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1526 | } |
| 1527 | } |
| 1528 | } |
| 1529 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1530 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1531 | DCHECK(location.IsRegister()); |
| 1532 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1533 | } |
| 1534 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1535 | void CodeGeneratorX86_64::MoveLocation( |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1536 | Location dst, Location src, DataType::Type dst_type ATTRIBUTE_UNUSED) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1537 | Move(dst, src); |
| 1538 | } |
| 1539 | |
| 1540 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1541 | if (location.IsRegister()) { |
| 1542 | locations->AddTemp(location); |
| 1543 | } else { |
| 1544 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1545 | } |
| 1546 | } |
| 1547 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1548 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1549 | if (successor->IsExitBlock()) { |
| 1550 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1551 | return; // no code needed |
| 1552 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1553 | |
| 1554 | HBasicBlock* block = got->GetBlock(); |
| 1555 | HInstruction* previous = got->GetPrevious(); |
| 1556 | |
| 1557 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1558 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1559 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1560 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), 0)); |
Mathieu Chartier | 7f8678e | 2019-08-30 16:22:28 -0700 | [diff] [blame] | 1561 | NearLabel overflow; |
| 1562 | __ cmpw(Address(CpuRegister(TMP), ArtMethod::HotnessCountOffset().Int32Value()), |
| 1563 | Immediate(ArtMethod::MaxCounter())); |
| 1564 | __ j(kEqual, &overflow); |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1565 | __ addw(Address(CpuRegister(TMP), ArtMethod::HotnessCountOffset().Int32Value()), |
| 1566 | Immediate(1)); |
Mathieu Chartier | 7f8678e | 2019-08-30 16:22:28 -0700 | [diff] [blame] | 1567 | __ Bind(&overflow); |
Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1568 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1569 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1570 | return; |
| 1571 | } |
| 1572 | |
| 1573 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1574 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1575 | } |
| 1576 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1577 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1578 | } |
| 1579 | } |
| 1580 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1581 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1582 | got->SetLocations(nullptr); |
| 1583 | } |
| 1584 | |
| 1585 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1586 | HandleGoto(got, got->GetSuccessor()); |
| 1587 | } |
| 1588 | |
| 1589 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1590 | try_boundary->SetLocations(nullptr); |
| 1591 | } |
| 1592 | |
| 1593 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1594 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1595 | if (!successor->IsExitBlock()) { |
| 1596 | HandleGoto(try_boundary, successor); |
| 1597 | } |
| 1598 | } |
| 1599 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1600 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1601 | exit->SetLocations(nullptr); |
| 1602 | } |
| 1603 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1604 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1605 | } |
| 1606 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1607 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1608 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1609 | LabelType* true_label, |
| 1610 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1611 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1612 | __ j(kUnordered, true_label); |
| 1613 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1614 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1615 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1616 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1617 | } |
| 1618 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1619 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1620 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1621 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1622 | Location left = locations->InAt(0); |
| 1623 | Location right = locations->InAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1624 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1625 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1626 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1627 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1628 | case DataType::Type::kInt8: |
| 1629 | case DataType::Type::kUint16: |
| 1630 | case DataType::Type::kInt16: |
| 1631 | case DataType::Type::kInt32: |
| 1632 | case DataType::Type::kReference: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1633 | codegen_->GenerateIntCompare(left, right); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1634 | break; |
| 1635 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1636 | case DataType::Type::kInt64: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1637 | codegen_->GenerateLongCompare(left, right); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1638 | break; |
| 1639 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1640 | case DataType::Type::kFloat32: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1641 | if (right.IsFpuRegister()) { |
| 1642 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1643 | } else if (right.IsConstant()) { |
| 1644 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1645 | codegen_->LiteralFloatAddress( |
| 1646 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1647 | } else { |
| 1648 | DCHECK(right.IsStackSlot()); |
| 1649 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1650 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1651 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1652 | break; |
| 1653 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1654 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1655 | if (right.IsFpuRegister()) { |
| 1656 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1657 | } else if (right.IsConstant()) { |
| 1658 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1659 | codegen_->LiteralDoubleAddress( |
| 1660 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1661 | } else { |
| 1662 | DCHECK(right.IsDoubleStackSlot()); |
| 1663 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1664 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1665 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1666 | break; |
| 1667 | } |
| 1668 | default: |
| 1669 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | template<class LabelType> |
| 1674 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1675 | LabelType* true_target_in, |
| 1676 | LabelType* false_target_in) { |
| 1677 | // Generated branching requires both targets to be explicit. If either of the |
| 1678 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1679 | LabelType fallthrough_target; |
| 1680 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1681 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1682 | |
| 1683 | // Generate the comparison to set the CC. |
| 1684 | GenerateCompareTest(condition); |
| 1685 | |
| 1686 | // Now generate the correct jump(s). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1687 | DataType::Type type = condition->InputAt(0)->GetType(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1688 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1689 | case DataType::Type::kInt64: { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1690 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1691 | break; |
| 1692 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1693 | case DataType::Type::kFloat32: { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1694 | GenerateFPJumps(condition, true_target, false_target); |
| 1695 | break; |
| 1696 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1697 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1698 | GenerateFPJumps(condition, true_target, false_target); |
| 1699 | break; |
| 1700 | } |
| 1701 | default: |
| 1702 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1703 | } |
| 1704 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1705 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1706 | __ jmp(false_target); |
| 1707 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1708 | |
| 1709 | if (fallthrough_target.IsLinked()) { |
| 1710 | __ Bind(&fallthrough_target); |
| 1711 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1712 | } |
| 1713 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1714 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1715 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1716 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1717 | // conditions if they are materialized due to the complex branching. |
| 1718 | return cond->IsCondition() && |
| 1719 | cond->GetNext() == branch && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1720 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1723 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1724 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1725 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1726 | LabelType* true_target, |
| 1727 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1728 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1729 | |
| 1730 | if (true_target == nullptr && false_target == nullptr) { |
| 1731 | // Nothing to do. The code always falls through. |
| 1732 | return; |
| 1733 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1734 | // Constant condition, statically compared against "true" (integer value 1). |
| 1735 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1736 | if (true_target != nullptr) { |
| 1737 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1738 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1739 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1740 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1741 | if (false_target != nullptr) { |
| 1742 | __ jmp(false_target); |
| 1743 | } |
| 1744 | } |
| 1745 | return; |
| 1746 | } |
| 1747 | |
| 1748 | // The following code generates these patterns: |
| 1749 | // (1) true_target == nullptr && false_target != nullptr |
| 1750 | // - opposite condition true => branch to false_target |
| 1751 | // (2) true_target != nullptr && false_target == nullptr |
| 1752 | // - condition true => branch to true_target |
| 1753 | // (3) true_target != nullptr && false_target != nullptr |
| 1754 | // - condition true => branch to true_target |
| 1755 | // - branch to false_target |
| 1756 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1757 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1758 | if (true_target == nullptr) { |
| 1759 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1760 | } else { |
| 1761 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1762 | } |
| 1763 | } else { |
| 1764 | // Materialized condition, compare against 0. |
| 1765 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1766 | if (lhs.IsRegister()) { |
| 1767 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1768 | } else { |
| 1769 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1770 | } |
| 1771 | if (true_target == nullptr) { |
| 1772 | __ j(kEqual, false_target); |
| 1773 | } else { |
| 1774 | __ j(kNotEqual, true_target); |
| 1775 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1776 | } |
| 1777 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1778 | // Condition has not been materialized, use its inputs as the |
| 1779 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1780 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1781 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1782 | // If this is a long or FP comparison that has been folded into |
| 1783 | // the HCondition, generate the comparison directly. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1784 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1785 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1786 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1787 | return; |
| 1788 | } |
| 1789 | |
| 1790 | Location lhs = condition->GetLocations()->InAt(0); |
| 1791 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1792 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1793 | if (true_target == nullptr) { |
| 1794 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1795 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1796 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1797 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1798 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1799 | |
| 1800 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1801 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1802 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1803 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1807 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1808 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1809 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1810 | locations->SetInAt(0, Location::Any()); |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1815 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1816 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1817 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1818 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1819 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1820 | nullptr : codegen_->GetLabelOf(false_successor); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1821 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1825 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1826 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1827 | InvokeRuntimeCallingConvention calling_convention; |
| 1828 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1829 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1830 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1831 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1832 | locations->SetInAt(0, Location::Any()); |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1837 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1838 | GenerateTestAndBranch<Label>(deoptimize, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1839 | /* condition_input_index= */ 0, |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1840 | slow_path->GetEntryLabel(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1841 | /* false_target= */ nullptr); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1844 | void LocationsBuilderX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1845 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1846 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1847 | locations->SetOut(Location::RequiresRegister()); |
| 1848 | } |
| 1849 | |
| 1850 | void InstructionCodeGeneratorX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1851 | __ movl(flag->GetLocations()->Out().AsRegister<CpuRegister>(), |
| 1852 | Address(CpuRegister(RSP), codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1853 | } |
| 1854 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1855 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1856 | // There are no conditional move instructions for XMMs. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1857 | if (DataType::IsFloatingPointType(select->GetType())) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1858 | return false; |
| 1859 | } |
| 1860 | |
| 1861 | // A FP condition doesn't generate the single CC that we need. |
| 1862 | HInstruction* condition = select->GetCondition(); |
| 1863 | if (condition->IsCondition() && |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1864 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1865 | return false; |
| 1866 | } |
| 1867 | |
| 1868 | // We can generate a CMOV for this Select. |
| 1869 | return true; |
| 1870 | } |
| 1871 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1872 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1873 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1874 | if (DataType::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1875 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1876 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1877 | } else { |
| 1878 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1879 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1880 | if (select->InputAt(1)->IsConstant()) { |
| 1881 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1882 | } else { |
| 1883 | locations->SetInAt(1, Location::Any()); |
| 1884 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1885 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1886 | locations->SetInAt(1, Location::Any()); |
| 1887 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1888 | } |
| 1889 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1890 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1891 | } |
| 1892 | locations->SetOut(Location::SameAsFirstInput()); |
| 1893 | } |
| 1894 | |
| 1895 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1896 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1897 | if (SelectCanUseCMOV(select)) { |
| 1898 | // If both the condition and the source types are integer, we can generate |
| 1899 | // a CMOV to implement Select. |
| 1900 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1901 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1902 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1903 | |
| 1904 | HInstruction* select_condition = select->GetCondition(); |
| 1905 | Condition cond = kNotEqual; |
| 1906 | |
| 1907 | // Figure out how to test the 'condition'. |
| 1908 | if (select_condition->IsCondition()) { |
| 1909 | HCondition* condition = select_condition->AsCondition(); |
| 1910 | if (!condition->IsEmittedAtUseSite()) { |
| 1911 | // This was a previously materialized condition. |
| 1912 | // Can we use the existing condition code? |
| 1913 | if (AreEflagsSetFrom(condition, select)) { |
| 1914 | // Materialization was the previous instruction. Condition codes are right. |
| 1915 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1916 | } else { |
| 1917 | // No, we have to recreate the condition code. |
| 1918 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1919 | __ testl(cond_reg, cond_reg); |
| 1920 | } |
| 1921 | } else { |
| 1922 | GenerateCompareTest(condition); |
| 1923 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1924 | } |
| 1925 | } else { |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1926 | // Must be a Boolean condition, which needs to be compared to 0. |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1927 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1928 | __ testl(cond_reg, cond_reg); |
| 1929 | } |
| 1930 | |
| 1931 | // If the condition is true, overwrite the output, which already contains false. |
| 1932 | // Generate the correct sized CMOV. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1933 | bool is_64_bit = DataType::Is64BitType(select->GetType()); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1934 | if (value_true_loc.IsRegister()) { |
| 1935 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1936 | } else { |
| 1937 | __ cmov(cond, |
| 1938 | value_false, |
| 1939 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1940 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1941 | } else { |
| 1942 | NearLabel false_target; |
| 1943 | GenerateTestAndBranch<NearLabel>(select, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1944 | /* condition_input_index= */ 2, |
| 1945 | /* true_target= */ nullptr, |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1946 | &false_target); |
| 1947 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1948 | __ Bind(&false_target); |
| 1949 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1952 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1953 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1956 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1957 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | void CodeGeneratorX86_64::GenerateNop() { |
| 1961 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1964 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1965 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1966 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1967 | // Handle the long/FP comparisons made in instruction simplification. |
| 1968 | switch (cond->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1969 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1970 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1971 | locations->SetInAt(1, Location::Any()); |
| 1972 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1973 | case DataType::Type::kFloat32: |
| 1974 | case DataType::Type::kFloat64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1975 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1976 | locations->SetInAt(1, Location::Any()); |
| 1977 | break; |
| 1978 | default: |
| 1979 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1980 | locations->SetInAt(1, Location::Any()); |
| 1981 | break; |
| 1982 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1983 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1984 | locations->SetOut(Location::RequiresRegister()); |
| 1985 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1986 | } |
| 1987 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1988 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1989 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1990 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1991 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1992 | |
| 1993 | LocationSummary* locations = cond->GetLocations(); |
| 1994 | Location lhs = locations->InAt(0); |
| 1995 | Location rhs = locations->InAt(1); |
| 1996 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1997 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1998 | |
| 1999 | switch (cond->InputAt(0)->GetType()) { |
| 2000 | default: |
| 2001 | // Integer case. |
| 2002 | |
| 2003 | // Clear output register: setcc only sets the low byte. |
| 2004 | __ xorl(reg, reg); |
| 2005 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2006 | codegen_->GenerateIntCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2007 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2008 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2009 | case DataType::Type::kInt64: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2010 | // Clear output register: setcc only sets the low byte. |
| 2011 | __ xorl(reg, reg); |
| 2012 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2013 | codegen_->GenerateLongCompare(lhs, rhs); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2014 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2015 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2016 | case DataType::Type::kFloat32: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2017 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 2018 | if (rhs.IsConstant()) { |
| 2019 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 2020 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 2021 | } else if (rhs.IsStackSlot()) { |
| 2022 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 2023 | } else { |
| 2024 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 2025 | } |
| 2026 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2027 | break; |
| 2028 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2029 | case DataType::Type::kFloat64: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2030 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 2031 | if (rhs.IsConstant()) { |
| 2032 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2033 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 2034 | } else if (rhs.IsDoubleStackSlot()) { |
| 2035 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 2036 | } else { |
| 2037 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 2038 | } |
| 2039 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2040 | break; |
| 2041 | } |
| 2042 | } |
| 2043 | |
| 2044 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2045 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2046 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2047 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2048 | __ Bind(&false_label); |
| 2049 | __ xorl(reg, reg); |
| 2050 | __ jmp(&done_label); |
| 2051 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2052 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2053 | __ Bind(&true_label); |
| 2054 | __ movl(reg, Immediate(1)); |
| 2055 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2059 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2063 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2067 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2068 | } |
| 2069 | |
| 2070 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2071 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2075 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2079 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2083 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2087 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2091 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2095 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2099 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2103 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2104 | } |
| 2105 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2106 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2107 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2111 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2115 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2119 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2123 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2127 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2131 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2135 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2138 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2139 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2140 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2141 | switch (compare->InputAt(0)->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2142 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2143 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2144 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2145 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2146 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2147 | case DataType::Type::kInt32: |
| 2148 | case DataType::Type::kInt64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2149 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2150 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2151 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2152 | break; |
| 2153 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2154 | case DataType::Type::kFloat32: |
| 2155 | case DataType::Type::kFloat64: { |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2156 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2157 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2158 | locations->SetOut(Location::RequiresRegister()); |
| 2159 | break; |
| 2160 | } |
| 2161 | default: |
| 2162 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2163 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2167 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2168 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2169 | Location left = locations->InAt(0); |
| 2170 | Location right = locations->InAt(1); |
| 2171 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2172 | NearLabel less, greater, done; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2173 | DataType::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2174 | Condition less_cond = kLess; |
| 2175 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2176 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2177 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2178 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2179 | case DataType::Type::kInt8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2180 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2181 | case DataType::Type::kInt16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2182 | case DataType::Type::kInt32: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2183 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2184 | break; |
| 2185 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2186 | case DataType::Type::kInt64: { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2187 | codegen_->GenerateLongCompare(left, right); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2188 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2189 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2190 | case DataType::Type::kFloat32: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2191 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2192 | if (right.IsConstant()) { |
| 2193 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2194 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2195 | } else if (right.IsStackSlot()) { |
| 2196 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2197 | } else { |
| 2198 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2199 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2200 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2201 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2202 | break; |
| 2203 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2204 | case DataType::Type::kFloat64: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2205 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2206 | if (right.IsConstant()) { |
| 2207 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2208 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2209 | } else if (right.IsDoubleStackSlot()) { |
| 2210 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2211 | } else { |
| 2212 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2213 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2214 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2215 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2216 | break; |
| 2217 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2218 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2219 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2220 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2221 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2222 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2223 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2224 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2225 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2226 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2227 | __ movl(out, Immediate(1)); |
| 2228 | __ jmp(&done); |
| 2229 | |
| 2230 | __ Bind(&less); |
| 2231 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2232 | |
| 2233 | __ Bind(&done); |
| 2234 | } |
| 2235 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2236 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2237 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2238 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2239 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2240 | } |
| 2241 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2242 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2243 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2244 | } |
| 2245 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2246 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2247 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2248 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2249 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2250 | } |
| 2251 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2252 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2253 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2256 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2257 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2258 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2259 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2260 | } |
| 2261 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2262 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2263 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2264 | } |
| 2265 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2266 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2267 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2268 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2269 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2270 | } |
| 2271 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2272 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2273 | // Will be generated at use site. |
| 2274 | } |
| 2275 | |
| 2276 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2277 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2278 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2279 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2280 | } |
| 2281 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2282 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2283 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2284 | // Will be generated at use site. |
| 2285 | } |
| 2286 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2287 | void LocationsBuilderX86_64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2288 | constructor_fence->SetLocations(nullptr); |
| 2289 | } |
| 2290 | |
| 2291 | void InstructionCodeGeneratorX86_64::VisitConstructorFence( |
| 2292 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2293 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2294 | } |
| 2295 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2296 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2297 | memory_barrier->SetLocations(nullptr); |
| 2298 | } |
| 2299 | |
| 2300 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2301 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2302 | } |
| 2303 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2304 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2305 | ret->SetLocations(nullptr); |
| 2306 | } |
| 2307 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2308 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2309 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2313 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2314 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2315 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2316 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2317 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2318 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2319 | case DataType::Type::kInt8: |
| 2320 | case DataType::Type::kUint16: |
| 2321 | case DataType::Type::kInt16: |
| 2322 | case DataType::Type::kInt32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2323 | case DataType::Type::kInt64: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2324 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2325 | break; |
| 2326 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2327 | case DataType::Type::kFloat32: |
| 2328 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2329 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2330 | break; |
| 2331 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2332 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2333 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2334 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2338 | if (kIsDebugBuild) { |
| 2339 | switch (ret->InputAt(0)->GetType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2340 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2341 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2342 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2343 | case DataType::Type::kInt8: |
| 2344 | case DataType::Type::kUint16: |
| 2345 | case DataType::Type::kInt16: |
| 2346 | case DataType::Type::kInt32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2347 | case DataType::Type::kInt64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2348 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2349 | break; |
| 2350 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2351 | case DataType::Type::kFloat32: |
| 2352 | case DataType::Type::kFloat64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2353 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2354 | XMM0); |
| 2355 | break; |
| 2356 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2357 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2358 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2359 | } |
| 2360 | } |
| 2361 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2362 | } |
| 2363 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2364 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(DataType::Type type) const { |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2365 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2366 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2367 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2368 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2369 | case DataType::Type::kInt8: |
| 2370 | case DataType::Type::kUint16: |
| 2371 | case DataType::Type::kInt16: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2372 | case DataType::Type::kUint32: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2373 | case DataType::Type::kInt32: |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2374 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2375 | case DataType::Type::kInt64: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2376 | return Location::RegisterLocation(RAX); |
| 2377 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2378 | case DataType::Type::kVoid: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2379 | return Location::NoLocation(); |
| 2380 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2381 | case DataType::Type::kFloat64: |
| 2382 | case DataType::Type::kFloat32: |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2383 | return Location::FpuRegisterLocation(XMM0); |
| 2384 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2385 | |
| 2386 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2390 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2391 | } |
| 2392 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2393 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(DataType::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2394 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2395 | case DataType::Type::kReference: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2396 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2397 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2398 | case DataType::Type::kInt8: |
| 2399 | case DataType::Type::kUint16: |
| 2400 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2401 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2402 | uint32_t index = gp_index_++; |
| 2403 | stack_index_++; |
| 2404 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2405 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2406 | } else { |
| 2407 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2408 | } |
| 2409 | } |
| 2410 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2411 | case DataType::Type::kInt64: { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2412 | uint32_t index = gp_index_; |
| 2413 | stack_index_ += 2; |
| 2414 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2415 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2416 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2417 | } else { |
| 2418 | gp_index_ += 2; |
| 2419 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2420 | } |
| 2421 | } |
| 2422 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2423 | case DataType::Type::kFloat32: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2424 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2425 | stack_index_++; |
| 2426 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2427 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2428 | } else { |
| 2429 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2430 | } |
| 2431 | } |
| 2432 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2433 | case DataType::Type::kFloat64: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2434 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2435 | stack_index_ += 2; |
| 2436 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2437 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2438 | } else { |
| 2439 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2440 | } |
| 2441 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2442 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2443 | case DataType::Type::kUint32: |
| 2444 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2445 | case DataType::Type::kVoid: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2446 | LOG(FATAL) << "Unexpected parameter type " << type; |
Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 2447 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2448 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2449 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2450 | } |
| 2451 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2452 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2453 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2454 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2455 | // the method_idx. |
| 2456 | HandleInvoke(invoke); |
| 2457 | } |
| 2458 | |
| 2459 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2460 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2461 | } |
| 2462 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2463 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2464 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2465 | // art::PrepareForRegisterAllocation. |
| 2466 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2467 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2468 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2469 | if (intrinsic.TryDispatch(invoke)) { |
| 2470 | return; |
| 2471 | } |
| 2472 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2473 | HandleInvoke(invoke); |
| 2474 | } |
| 2475 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2476 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2477 | if (invoke->GetLocations()->Intrinsified()) { |
| 2478 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2479 | intrinsic.Dispatch(invoke); |
| 2480 | return true; |
| 2481 | } |
| 2482 | return false; |
| 2483 | } |
| 2484 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2485 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2486 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2487 | // art::PrepareForRegisterAllocation. |
| 2488 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2489 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2490 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2491 | return; |
| 2492 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2493 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2494 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2495 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2496 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2497 | } |
| 2498 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2499 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2500 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2501 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2502 | } |
| 2503 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2504 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2505 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2506 | if (intrinsic.TryDispatch(invoke)) { |
| 2507 | return; |
| 2508 | } |
| 2509 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2510 | HandleInvoke(invoke); |
| 2511 | } |
| 2512 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2513 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2514 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2515 | return; |
| 2516 | } |
| 2517 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2518 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2519 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2520 | } |
| 2521 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2522 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2523 | HandleInvoke(invoke); |
| 2524 | // Add the hidden argument. |
| 2525 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2526 | } |
| 2527 | |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame^] | 2528 | void CodeGeneratorX86_64::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 2529 | CpuRegister klass) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2530 | DCHECK_EQ(RDI, klass.AsRegister()); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame^] | 2531 | // We know the destination of an intrinsic, so no need to record inline |
| 2532 | // caches. |
| 2533 | if (!instruction->GetLocations()->Intrinsified() && |
| 2534 | GetCompilerOptions().IsBaseline() && |
| 2535 | !Runtime::Current()->IsAotCompiler()) { |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2536 | ScopedObjectAccess soa(Thread::Current()); |
| 2537 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame^] | 2538 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2539 | uint64_t address = reinterpret_cast64<uint64_t>(cache); |
| 2540 | NearLabel done; |
| 2541 | __ movq(CpuRegister(TMP), Immediate(address)); |
| 2542 | // Fast path for a monomorphic cache. |
| 2543 | __ cmpl(Address(CpuRegister(TMP), InlineCache::ClassesOffset().Int32Value()), klass); |
| 2544 | __ j(kEqual, &done); |
| 2545 | GenerateInvokeRuntime( |
| 2546 | GetThreadOffset<kX86_64PointerSize>(kQuickUpdateInlineCache).Int32Value()); |
| 2547 | __ Bind(&done); |
| 2548 | } |
| 2549 | } |
| 2550 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2551 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2552 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2553 | LocationSummary* locations = invoke->GetLocations(); |
| 2554 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2555 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2556 | Location receiver = locations->InAt(0); |
| 2557 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2558 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2559 | if (receiver.IsStackSlot()) { |
| 2560 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2561 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2562 | __ movl(temp, Address(temp, class_offset)); |
| 2563 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2564 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2565 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2566 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2567 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2568 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2569 | // emit a read barrier for the previous class reference load. |
| 2570 | // However this is not required in practice, as this is an |
| 2571 | // intermediate/temporary reference and because the current |
| 2572 | // concurrent copying collector keeps the from-space memory |
| 2573 | // intact/accessible until the end of the marking phase (the |
| 2574 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2575 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2576 | |
Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame^] | 2577 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2578 | |
| 2579 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2580 | // won't be modified thereafter, before the `call` instruction. |
| 2581 | // We also di it after MaybeGenerateInlineCache that may use RAX. |
| 2582 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
| 2583 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
| 2584 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2585 | // temp = temp->GetAddressOfIMT() |
| 2586 | __ movq(temp, |
| 2587 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2588 | // temp = temp->GetImtEntryAt(method_offset); |
| 2589 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2590 | invoke->GetImtIndex(), kX86_64PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2591 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2592 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2593 | // call temp->GetEntryPoint(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2594 | __ call(Address( |
| 2595 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2596 | |
| 2597 | DCHECK(!codegen_->IsLeafMethod()); |
| 2598 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2599 | } |
| 2600 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2601 | void LocationsBuilderX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2602 | HandleInvoke(invoke); |
| 2603 | } |
| 2604 | |
| 2605 | void InstructionCodeGeneratorX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2606 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2607 | } |
| 2608 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2609 | void LocationsBuilderX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2610 | HandleInvoke(invoke); |
| 2611 | } |
| 2612 | |
| 2613 | void InstructionCodeGeneratorX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2614 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2615 | } |
| 2616 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2617 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2618 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2619 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2620 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2621 | case DataType::Type::kInt32: |
| 2622 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2623 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2624 | locations->SetOut(Location::SameAsFirstInput()); |
| 2625 | break; |
| 2626 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2627 | case DataType::Type::kFloat32: |
| 2628 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2629 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2630 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2631 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2632 | break; |
| 2633 | |
| 2634 | default: |
| 2635 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2636 | } |
| 2637 | } |
| 2638 | |
| 2639 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2640 | LocationSummary* locations = neg->GetLocations(); |
| 2641 | Location out = locations->Out(); |
| 2642 | Location in = locations->InAt(0); |
| 2643 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2644 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2645 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2646 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2647 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2648 | break; |
| 2649 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2650 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2651 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2652 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2653 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2654 | break; |
| 2655 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2656 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2657 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2658 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2659 | // Implement float negation with an exclusive or with value |
| 2660 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2661 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2662 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2663 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2664 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2665 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2666 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2667 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2668 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2669 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2670 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2671 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2672 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2673 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2674 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2675 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2676 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2677 | |
| 2678 | default: |
| 2679 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2680 | } |
| 2681 | } |
| 2682 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2683 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2684 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2685 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2686 | DataType::Type result_type = conversion->GetResultType(); |
| 2687 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2688 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2689 | << input_type << " -> " << result_type; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2690 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2691 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2692 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2693 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2694 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2695 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2696 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2697 | locations->SetInAt(0, Location::Any()); |
| 2698 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2699 | break; |
| 2700 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2701 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2702 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2703 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2704 | locations->SetInAt(0, Location::Any()); |
| 2705 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2706 | break; |
| 2707 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2708 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2709 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2710 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2711 | break; |
| 2712 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2713 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2714 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2715 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2716 | break; |
| 2717 | |
| 2718 | default: |
| 2719 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2720 | << " to " << result_type; |
| 2721 | } |
| 2722 | break; |
| 2723 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2724 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2725 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2726 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2727 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2728 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2729 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2730 | case DataType::Type::kInt16: |
| 2731 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2732 | // TODO: We would benefit from a (to-be-implemented) |
| 2733 | // Location::RegisterOrStackSlot requirement for this input. |
| 2734 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2735 | locations->SetOut(Location::RequiresRegister()); |
| 2736 | break; |
| 2737 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2738 | case DataType::Type::kFloat32: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2739 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2740 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2741 | break; |
| 2742 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2743 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2744 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2745 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2746 | break; |
| 2747 | |
| 2748 | default: |
| 2749 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2750 | << " to " << result_type; |
| 2751 | } |
| 2752 | break; |
| 2753 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2754 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2755 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2756 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2757 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2758 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2759 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2760 | case DataType::Type::kInt16: |
| 2761 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2762 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2763 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2764 | break; |
| 2765 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2766 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2767 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2768 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2769 | break; |
| 2770 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2771 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2772 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2773 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2774 | break; |
| 2775 | |
| 2776 | default: |
| 2777 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2778 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2779 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2780 | break; |
| 2781 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2782 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2783 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2784 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2785 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2786 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2787 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2788 | case DataType::Type::kInt16: |
| 2789 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2790 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2791 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2792 | break; |
| 2793 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2794 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2795 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2796 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2797 | break; |
| 2798 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2799 | case DataType::Type::kFloat32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2800 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2801 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2802 | break; |
| 2803 | |
| 2804 | default: |
| 2805 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2806 | << " to " << result_type; |
| 2807 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2808 | break; |
| 2809 | |
| 2810 | default: |
| 2811 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2812 | << " to " << result_type; |
| 2813 | } |
| 2814 | } |
| 2815 | |
| 2816 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2817 | LocationSummary* locations = conversion->GetLocations(); |
| 2818 | Location out = locations->Out(); |
| 2819 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2820 | DataType::Type result_type = conversion->GetResultType(); |
| 2821 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2822 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2823 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2824 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2825 | case DataType::Type::kUint8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2826 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2827 | case DataType::Type::kInt8: |
| 2828 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2829 | case DataType::Type::kInt16: |
| 2830 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2831 | case DataType::Type::kInt64: |
| 2832 | if (in.IsRegister()) { |
| 2833 | __ movzxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 2834 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 2835 | __ movzxb(out.AsRegister<CpuRegister>(), |
| 2836 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2837 | } else { |
| 2838 | __ movl(out.AsRegister<CpuRegister>(), |
| 2839 | Immediate(static_cast<uint8_t>(Int64FromConstant(in.GetConstant())))); |
| 2840 | } |
| 2841 | break; |
| 2842 | |
| 2843 | default: |
| 2844 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2845 | << " to " << result_type; |
| 2846 | } |
| 2847 | break; |
| 2848 | |
| 2849 | case DataType::Type::kInt8: |
| 2850 | switch (input_type) { |
| 2851 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2852 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2853 | case DataType::Type::kInt16: |
| 2854 | case DataType::Type::kInt32: |
| 2855 | case DataType::Type::kInt64: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2856 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2857 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2858 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2859 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2860 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2861 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2862 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2863 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2864 | } |
| 2865 | break; |
| 2866 | |
| 2867 | default: |
| 2868 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2869 | << " to " << result_type; |
| 2870 | } |
| 2871 | break; |
| 2872 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2873 | case DataType::Type::kUint16: |
| 2874 | switch (input_type) { |
| 2875 | case DataType::Type::kInt8: |
| 2876 | case DataType::Type::kInt16: |
| 2877 | case DataType::Type::kInt32: |
| 2878 | case DataType::Type::kInt64: |
| 2879 | if (in.IsRegister()) { |
| 2880 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 2881 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 2882 | __ movzxw(out.AsRegister<CpuRegister>(), |
| 2883 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2884 | } else { |
| 2885 | __ movl(out.AsRegister<CpuRegister>(), |
| 2886 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
| 2887 | } |
| 2888 | break; |
| 2889 | |
| 2890 | default: |
| 2891 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2892 | << " to " << result_type; |
| 2893 | } |
| 2894 | break; |
| 2895 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2896 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2897 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2898 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2899 | case DataType::Type::kInt32: |
| 2900 | case DataType::Type::kInt64: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2901 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2902 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2903 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2904 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2905 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2906 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2907 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2908 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2909 | } |
| 2910 | break; |
| 2911 | |
| 2912 | default: |
| 2913 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2914 | << " to " << result_type; |
| 2915 | } |
| 2916 | break; |
| 2917 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2918 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2919 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2920 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2921 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2922 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2923 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2924 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2925 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2926 | } else { |
| 2927 | DCHECK(in.IsConstant()); |
| 2928 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2929 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2930 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2931 | } |
| 2932 | break; |
| 2933 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2934 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2935 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2936 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2937 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2938 | |
| 2939 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2940 | // if input >= (float)INT_MAX goto done |
Nick Desaulniers | 98e97c6 | 2019-10-18 14:25:19 -0700 | [diff] [blame] | 2941 | __ comiss(input, codegen_->LiteralFloatAddress(static_cast<float>(kPrimIntMax))); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2942 | __ j(kAboveEqual, &done); |
| 2943 | // if input == NaN goto nan |
| 2944 | __ j(kUnordered, &nan); |
| 2945 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2946 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2947 | __ jmp(&done); |
| 2948 | __ Bind(&nan); |
| 2949 | // output = 0 |
| 2950 | __ xorl(output, output); |
| 2951 | __ Bind(&done); |
| 2952 | break; |
| 2953 | } |
| 2954 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2955 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2956 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2957 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2958 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2959 | |
| 2960 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2961 | // if input >= (double)INT_MAX goto done |
| 2962 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2963 | __ j(kAboveEqual, &done); |
| 2964 | // if input == NaN goto nan |
| 2965 | __ j(kUnordered, &nan); |
| 2966 | // output = double-to-int-truncate(input) |
| 2967 | __ cvttsd2si(output, input); |
| 2968 | __ jmp(&done); |
| 2969 | __ Bind(&nan); |
| 2970 | // output = 0 |
| 2971 | __ xorl(output, output); |
| 2972 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2973 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2974 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2975 | |
| 2976 | default: |
| 2977 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2978 | << " to " << result_type; |
| 2979 | } |
| 2980 | break; |
| 2981 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2982 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2983 | switch (input_type) { |
| 2984 | DCHECK(out.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2985 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2986 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2987 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2988 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2989 | case DataType::Type::kInt16: |
| 2990 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2991 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2992 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2993 | break; |
| 2994 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2995 | case DataType::Type::kFloat32: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2996 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2997 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2998 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2999 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3000 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 3001 | // if input >= (float)LONG_MAX goto done |
Nick Desaulniers | 98e97c6 | 2019-10-18 14:25:19 -0700 | [diff] [blame] | 3002 | __ comiss(input, codegen_->LiteralFloatAddress(static_cast<float>(kPrimLongMax))); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3003 | __ j(kAboveEqual, &done); |
| 3004 | // if input == NaN goto nan |
| 3005 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3006 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3007 | __ cvttss2si(output, input, true); |
| 3008 | __ jmp(&done); |
| 3009 | __ Bind(&nan); |
| 3010 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3011 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3012 | __ Bind(&done); |
| 3013 | break; |
| 3014 | } |
| 3015 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3016 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3017 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3018 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3019 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3020 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3021 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 3022 | // if input >= (double)LONG_MAX goto done |
Nick Desaulniers | 98e97c6 | 2019-10-18 14:25:19 -0700 | [diff] [blame] | 3023 | __ comisd(input, codegen_->LiteralDoubleAddress( |
| 3024 | static_cast<double>(kPrimLongMax))); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3025 | __ j(kAboveEqual, &done); |
| 3026 | // if input == NaN goto nan |
| 3027 | __ j(kUnordered, &nan); |
| 3028 | // output = double-to-long-truncate(input) |
| 3029 | __ cvttsd2si(output, input, true); |
| 3030 | __ jmp(&done); |
| 3031 | __ Bind(&nan); |
| 3032 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3033 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3034 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3035 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3036 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3037 | |
| 3038 | default: |
| 3039 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3040 | << " to " << result_type; |
| 3041 | } |
| 3042 | break; |
| 3043 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3044 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3045 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3046 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3047 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3048 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3049 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3050 | case DataType::Type::kInt16: |
| 3051 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3052 | if (in.IsRegister()) { |
| 3053 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3054 | } else if (in.IsConstant()) { |
| 3055 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3056 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3057 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3058 | } else { |
| 3059 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3060 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3061 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3062 | break; |
| 3063 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3064 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3065 | if (in.IsRegister()) { |
| 3066 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3067 | } else if (in.IsConstant()) { |
| 3068 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3069 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 3070 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3071 | } else { |
| 3072 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3073 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3074 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3075 | break; |
| 3076 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3077 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3078 | if (in.IsFpuRegister()) { |
| 3079 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3080 | } else if (in.IsConstant()) { |
| 3081 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 3082 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3083 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3084 | } else { |
| 3085 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 3086 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3087 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3088 | break; |
| 3089 | |
| 3090 | default: |
| 3091 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3092 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3093 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3094 | break; |
| 3095 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3096 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3097 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3098 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3099 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3100 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3101 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3102 | case DataType::Type::kInt16: |
| 3103 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3104 | if (in.IsRegister()) { |
| 3105 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3106 | } else if (in.IsConstant()) { |
| 3107 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3108 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3109 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3110 | } else { |
| 3111 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3112 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3113 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3114 | break; |
| 3115 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3116 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3117 | if (in.IsRegister()) { |
| 3118 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3119 | } else if (in.IsConstant()) { |
| 3120 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3121 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3122 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3123 | } else { |
| 3124 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3125 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3126 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3127 | break; |
| 3128 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3129 | case DataType::Type::kFloat32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3130 | if (in.IsFpuRegister()) { |
| 3131 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3132 | } else if (in.IsConstant()) { |
| 3133 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3134 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3135 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3136 | } else { |
| 3137 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3138 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3139 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3140 | break; |
| 3141 | |
| 3142 | default: |
| 3143 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3144 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3145 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3146 | break; |
| 3147 | |
| 3148 | default: |
| 3149 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3150 | << " to " << result_type; |
| 3151 | } |
| 3152 | } |
| 3153 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3154 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3155 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3156 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3157 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3158 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3159 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3160 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3161 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3162 | break; |
| 3163 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3164 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3165 | case DataType::Type::kInt64: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3166 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3167 | // 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] | 3168 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3169 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3170 | break; |
| 3171 | } |
| 3172 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3173 | case DataType::Type::kFloat64: |
| 3174 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3175 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3176 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3177 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3178 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3179 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3180 | |
| 3181 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3182 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3183 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3187 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3188 | Location first = locations->InAt(0); |
| 3189 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3190 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3191 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3192 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3193 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3194 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3195 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3196 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3197 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3198 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3199 | } else { |
| 3200 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3201 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3202 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3203 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3204 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3205 | __ addl(out.AsRegister<CpuRegister>(), |
| 3206 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3207 | } else { |
| 3208 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3209 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3210 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3211 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3212 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3213 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3214 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3215 | break; |
| 3216 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3217 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3218 | case DataType::Type::kInt64: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3219 | if (second.IsRegister()) { |
| 3220 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3221 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3222 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3223 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3224 | } else { |
| 3225 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3226 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3227 | } |
| 3228 | } else { |
| 3229 | DCHECK(second.IsConstant()); |
| 3230 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3231 | int32_t int32_value = Low32Bits(value); |
| 3232 | DCHECK_EQ(int32_value, value); |
| 3233 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3234 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3235 | } else { |
| 3236 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3237 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3238 | } |
| 3239 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3240 | break; |
| 3241 | } |
| 3242 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3243 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3244 | if (second.IsFpuRegister()) { |
| 3245 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3246 | } else if (second.IsConstant()) { |
| 3247 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3248 | codegen_->LiteralFloatAddress( |
| 3249 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3250 | } else { |
| 3251 | DCHECK(second.IsStackSlot()); |
| 3252 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3253 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3254 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3255 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3256 | } |
| 3257 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3258 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3259 | if (second.IsFpuRegister()) { |
| 3260 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3261 | } else if (second.IsConstant()) { |
| 3262 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3263 | codegen_->LiteralDoubleAddress( |
| 3264 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3265 | } else { |
| 3266 | DCHECK(second.IsDoubleStackSlot()); |
| 3267 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3268 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3269 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3270 | break; |
| 3271 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3272 | |
| 3273 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3274 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3275 | } |
| 3276 | } |
| 3277 | |
| 3278 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3279 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3280 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3281 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3282 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3283 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3284 | locations->SetInAt(1, Location::Any()); |
| 3285 | locations->SetOut(Location::SameAsFirstInput()); |
| 3286 | break; |
| 3287 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3288 | case DataType::Type::kInt64: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3289 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3290 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3291 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3292 | break; |
| 3293 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3294 | case DataType::Type::kFloat32: |
| 3295 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3296 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3297 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3298 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3299 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3300 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3301 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3302 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3303 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3307 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3308 | Location first = locations->InAt(0); |
| 3309 | Location second = locations->InAt(1); |
| 3310 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3311 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3312 | case DataType::Type::kInt32: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3313 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3314 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3315 | } else if (second.IsConstant()) { |
| 3316 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3317 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3318 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3319 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3320 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3321 | break; |
| 3322 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3323 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3324 | if (second.IsConstant()) { |
| 3325 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3326 | DCHECK(IsInt<32>(value)); |
| 3327 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3328 | } else { |
| 3329 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3330 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3331 | break; |
| 3332 | } |
| 3333 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3334 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3335 | if (second.IsFpuRegister()) { |
| 3336 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3337 | } else if (second.IsConstant()) { |
| 3338 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3339 | codegen_->LiteralFloatAddress( |
| 3340 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3341 | } else { |
| 3342 | DCHECK(second.IsStackSlot()); |
| 3343 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3344 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3345 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3346 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3347 | } |
| 3348 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3349 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3350 | if (second.IsFpuRegister()) { |
| 3351 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3352 | } else if (second.IsConstant()) { |
| 3353 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3354 | codegen_->LiteralDoubleAddress( |
| 3355 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3356 | } else { |
| 3357 | DCHECK(second.IsDoubleStackSlot()); |
| 3358 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3359 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3360 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3361 | break; |
| 3362 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3363 | |
| 3364 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3365 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3366 | } |
| 3367 | } |
| 3368 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3369 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3370 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3371 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3372 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3373 | case DataType::Type::kInt32: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3374 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3375 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3376 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3377 | // Can use 3 operand multiply. |
| 3378 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3379 | } else { |
| 3380 | locations->SetOut(Location::SameAsFirstInput()); |
| 3381 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3382 | break; |
| 3383 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3384 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3385 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3386 | locations->SetInAt(1, Location::Any()); |
| 3387 | if (mul->InputAt(1)->IsLongConstant() && |
| 3388 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3389 | // Can use 3 operand multiply. |
| 3390 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3391 | } else { |
| 3392 | locations->SetOut(Location::SameAsFirstInput()); |
| 3393 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3394 | break; |
| 3395 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3396 | case DataType::Type::kFloat32: |
| 3397 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3398 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3399 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3400 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3401 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3402 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3403 | |
| 3404 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3405 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3406 | } |
| 3407 | } |
| 3408 | |
| 3409 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3410 | LocationSummary* locations = mul->GetLocations(); |
| 3411 | Location first = locations->InAt(0); |
| 3412 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3413 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3414 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3415 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3416 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3417 | // problems where the output may not be the same as the first operand. |
| 3418 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3419 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3420 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3421 | } else if (second.IsRegister()) { |
| 3422 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3423 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3424 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3425 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3426 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3427 | __ imull(first.AsRegister<CpuRegister>(), |
| 3428 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3429 | } |
| 3430 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3431 | case DataType::Type::kInt64: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3432 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3433 | // problems where the output may not be the same as the first operand. |
| 3434 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3435 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3436 | if (IsInt<32>(value)) { |
| 3437 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3438 | Immediate(static_cast<int32_t>(value))); |
| 3439 | } else { |
| 3440 | // Have to use the constant area. |
| 3441 | DCHECK(first.Equals(out)); |
| 3442 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3443 | } |
| 3444 | } else if (second.IsRegister()) { |
| 3445 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3446 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3447 | } else { |
| 3448 | DCHECK(second.IsDoubleStackSlot()); |
| 3449 | DCHECK(first.Equals(out)); |
| 3450 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3451 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3452 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3453 | break; |
| 3454 | } |
| 3455 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3456 | case DataType::Type::kFloat32: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3457 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3458 | if (second.IsFpuRegister()) { |
| 3459 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3460 | } else if (second.IsConstant()) { |
| 3461 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3462 | codegen_->LiteralFloatAddress( |
| 3463 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3464 | } else { |
| 3465 | DCHECK(second.IsStackSlot()); |
| 3466 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3467 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3468 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3469 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3470 | } |
| 3471 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3472 | case DataType::Type::kFloat64: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3473 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3474 | if (second.IsFpuRegister()) { |
| 3475 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3476 | } else if (second.IsConstant()) { |
| 3477 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3478 | codegen_->LiteralDoubleAddress( |
| 3479 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3480 | } else { |
| 3481 | DCHECK(second.IsDoubleStackSlot()); |
| 3482 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3483 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3484 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3485 | break; |
| 3486 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3487 | |
| 3488 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3489 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3490 | } |
| 3491 | } |
| 3492 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3493 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3494 | uint32_t stack_adjustment, bool is_float) { |
| 3495 | if (source.IsStackSlot()) { |
| 3496 | DCHECK(is_float); |
| 3497 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3498 | } else if (source.IsDoubleStackSlot()) { |
| 3499 | DCHECK(!is_float); |
| 3500 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3501 | } else { |
| 3502 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3503 | if (is_float) { |
| 3504 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3505 | codegen_->Move(stack_temp, source); |
| 3506 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3507 | } else { |
| 3508 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3509 | codegen_->Move(stack_temp, source); |
| 3510 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3511 | } |
| 3512 | } |
| 3513 | } |
| 3514 | |
| 3515 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3516 | DataType::Type type = rem->GetResultType(); |
| 3517 | bool is_float = type == DataType::Type::kFloat32; |
| 3518 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3519 | LocationSummary* locations = rem->GetLocations(); |
| 3520 | Location first = locations->InAt(0); |
| 3521 | Location second = locations->InAt(1); |
| 3522 | Location out = locations->Out(); |
| 3523 | |
| 3524 | // Create stack space for 2 elements. |
| 3525 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3526 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3527 | |
| 3528 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3529 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3530 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3531 | |
| 3532 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3533 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3534 | __ Bind(&retry); |
| 3535 | __ fprem(); |
| 3536 | |
| 3537 | // Move FP status to AX. |
| 3538 | __ fstsw(); |
| 3539 | |
| 3540 | // And see if the argument reduction is complete. This is signaled by the |
| 3541 | // C2 FPU flag bit set to 0. |
| 3542 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3543 | __ j(kNotEqual, &retry); |
| 3544 | |
| 3545 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3546 | // Store FP top of stack to real stack. |
| 3547 | if (is_float) { |
| 3548 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3549 | } else { |
| 3550 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3551 | } |
| 3552 | |
| 3553 | // Pop the 2 items from the FP stack. |
| 3554 | __ fucompp(); |
| 3555 | |
| 3556 | // Load the value from the stack into an XMM register. |
| 3557 | DCHECK(out.IsFpuRegister()) << out; |
| 3558 | if (is_float) { |
| 3559 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3560 | } else { |
| 3561 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3562 | } |
| 3563 | |
| 3564 | // And remove the temporary stack space we allocated. |
| 3565 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3566 | } |
| 3567 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3568 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3569 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3570 | |
| 3571 | LocationSummary* locations = instruction->GetLocations(); |
| 3572 | Location second = locations->InAt(1); |
| 3573 | DCHECK(second.IsConstant()); |
| 3574 | |
| 3575 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3576 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3577 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3578 | |
| 3579 | DCHECK(imm == 1 || imm == -1); |
| 3580 | |
| 3581 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3582 | case DataType::Type::kInt32: { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3583 | if (instruction->IsRem()) { |
| 3584 | __ xorl(output_register, output_register); |
| 3585 | } else { |
| 3586 | __ movl(output_register, input_register); |
| 3587 | if (imm == -1) { |
| 3588 | __ negl(output_register); |
| 3589 | } |
| 3590 | } |
| 3591 | break; |
| 3592 | } |
| 3593 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3594 | case DataType::Type::kInt64: { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3595 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3596 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3597 | } else { |
| 3598 | __ movq(output_register, input_register); |
| 3599 | if (imm == -1) { |
| 3600 | __ negq(output_register); |
| 3601 | } |
| 3602 | } |
| 3603 | break; |
| 3604 | } |
| 3605 | |
| 3606 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3607 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3608 | } |
| 3609 | } |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3610 | void InstructionCodeGeneratorX86_64::RemByPowerOfTwo(HRem* instruction) { |
| 3611 | LocationSummary* locations = instruction->GetLocations(); |
| 3612 | Location second = locations->InAt(1); |
| 3613 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3614 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3615 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3616 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3617 | uint64_t abs_imm = AbsOrMin(imm); |
| 3618 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3619 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3620 | NearLabel done; |
| 3621 | __ movl(out, numerator); |
| 3622 | __ andl(out, Immediate(abs_imm-1)); |
| 3623 | __ j(Condition::kZero, &done); |
| 3624 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 3625 | __ testl(numerator, numerator); |
| 3626 | __ cmov(Condition::kLess, out, tmp, false); |
| 3627 | __ Bind(&done); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3628 | |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3629 | } else { |
| 3630 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3631 | codegen_->Load64BitValue(tmp, abs_imm - 1); |
| 3632 | NearLabel done; |
| 3633 | |
| 3634 | __ movq(out, numerator); |
| 3635 | __ andq(out, tmp); |
| 3636 | __ j(Condition::kZero, &done); |
| 3637 | __ movq(tmp, numerator); |
| 3638 | __ sarq(tmp, Immediate(63)); |
| 3639 | __ shlq(tmp, Immediate(WhichPowerOf2(abs_imm))); |
| 3640 | __ orq(out, tmp); |
| 3641 | __ Bind(&done); |
| 3642 | } |
| 3643 | } |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3644 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3645 | LocationSummary* locations = instruction->GetLocations(); |
| 3646 | Location second = locations->InAt(1); |
| 3647 | |
| 3648 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3649 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3650 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3651 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3652 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3653 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3654 | |
| 3655 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3656 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3657 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 3658 | // When denominator is equal to 2, we can add signed bit and numerator to tmp. |
| 3659 | // Below we are using addl instruction instead of cmov which give us 1 cycle benefit. |
| 3660 | if (abs_imm == 2) { |
| 3661 | __ leal(tmp, Address(numerator, 0)); |
| 3662 | __ shrl(tmp, Immediate(31)); |
| 3663 | __ addl(tmp, numerator); |
| 3664 | } else { |
| 3665 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
| 3666 | __ testl(numerator, numerator); |
| 3667 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3668 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3669 | int shift = CTZ(imm); |
| 3670 | __ sarl(tmp, Immediate(shift)); |
| 3671 | |
| 3672 | if (imm < 0) { |
| 3673 | __ negl(tmp); |
| 3674 | } |
| 3675 | |
| 3676 | __ movl(output_register, tmp); |
| 3677 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3678 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3679 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 3680 | if (abs_imm == 2) { |
| 3681 | __ movq(rdx, numerator); |
| 3682 | __ shrq(rdx, Immediate(63)); |
| 3683 | __ addq(rdx, numerator); |
| 3684 | } else { |
| 3685 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
| 3686 | __ addq(rdx, numerator); |
| 3687 | __ testq(numerator, numerator); |
| 3688 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3689 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3690 | int shift = CTZ(imm); |
| 3691 | __ sarq(rdx, Immediate(shift)); |
| 3692 | |
| 3693 | if (imm < 0) { |
| 3694 | __ negq(rdx); |
| 3695 | } |
| 3696 | |
| 3697 | __ movq(output_register, rdx); |
| 3698 | } |
| 3699 | } |
| 3700 | |
| 3701 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3702 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3703 | |
| 3704 | LocationSummary* locations = instruction->GetLocations(); |
| 3705 | Location second = locations->InAt(1); |
| 3706 | |
| 3707 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3708 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3709 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3710 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3711 | : locations->Out().AsRegister<CpuRegister>(); |
| 3712 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3713 | |
| 3714 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3715 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3716 | if (instruction->IsDiv()) { |
| 3717 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3718 | } else { |
| 3719 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3720 | } |
| 3721 | |
| 3722 | int64_t magic; |
| 3723 | int shift; |
| 3724 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3725 | // TODO: can these branches be written as one? |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3726 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3727 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3728 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3729 | CalculateMagicAndShiftForDivRem(imm, false /* is_long= */, &magic, &shift); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3730 | |
| 3731 | __ movl(numerator, eax); |
| 3732 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3733 | __ movl(eax, Immediate(magic)); |
| 3734 | __ imull(numerator); |
| 3735 | |
| 3736 | if (imm > 0 && magic < 0) { |
| 3737 | __ addl(edx, numerator); |
| 3738 | } else if (imm < 0 && magic > 0) { |
| 3739 | __ subl(edx, numerator); |
| 3740 | } |
| 3741 | |
| 3742 | if (shift != 0) { |
| 3743 | __ sarl(edx, Immediate(shift)); |
| 3744 | } |
| 3745 | |
| 3746 | __ movl(eax, edx); |
| 3747 | __ shrl(edx, Immediate(31)); |
| 3748 | __ addl(edx, eax); |
| 3749 | |
| 3750 | if (instruction->IsRem()) { |
| 3751 | __ movl(eax, numerator); |
| 3752 | __ imull(edx, Immediate(imm)); |
| 3753 | __ subl(eax, edx); |
| 3754 | __ movl(edx, eax); |
| 3755 | } else { |
| 3756 | __ movl(eax, edx); |
| 3757 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3758 | } else { |
| 3759 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3760 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3761 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3762 | |
| 3763 | CpuRegister rax = eax; |
| 3764 | CpuRegister rdx = edx; |
| 3765 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3766 | CalculateMagicAndShiftForDivRem(imm, true /* is_long= */, &magic, &shift); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3767 | |
| 3768 | // Save the numerator. |
| 3769 | __ movq(numerator, rax); |
| 3770 | |
| 3771 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3772 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3773 | |
| 3774 | // RDX:RAX = magic * numerator |
| 3775 | __ imulq(numerator); |
| 3776 | |
| 3777 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3778 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3779 | __ addq(rdx, numerator); |
| 3780 | } else if (imm < 0 && magic > 0) { |
| 3781 | // RDX -= numerator |
| 3782 | __ subq(rdx, numerator); |
| 3783 | } |
| 3784 | |
| 3785 | // Shift if needed. |
| 3786 | if (shift != 0) { |
| 3787 | __ sarq(rdx, Immediate(shift)); |
| 3788 | } |
| 3789 | |
| 3790 | // RDX += 1 if RDX < 0 |
| 3791 | __ movq(rax, rdx); |
| 3792 | __ shrq(rdx, Immediate(63)); |
| 3793 | __ addq(rdx, rax); |
| 3794 | |
| 3795 | if (instruction->IsRem()) { |
| 3796 | __ movq(rax, numerator); |
| 3797 | |
| 3798 | if (IsInt<32>(imm)) { |
| 3799 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3800 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3801 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | __ subq(rax, rdx); |
| 3805 | __ movq(rdx, rax); |
| 3806 | } else { |
| 3807 | __ movq(rax, rdx); |
| 3808 | } |
| 3809 | } |
| 3810 | } |
| 3811 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3812 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3813 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3814 | DataType::Type type = instruction->GetResultType(); |
| 3815 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3816 | |
| 3817 | bool is_div = instruction->IsDiv(); |
| 3818 | LocationSummary* locations = instruction->GetLocations(); |
| 3819 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3820 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3821 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3822 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3823 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3824 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3825 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3826 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3827 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3828 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3829 | if (imm == 0) { |
| 3830 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3831 | } else if (imm == 1 || imm == -1) { |
| 3832 | DivRemOneOrMinusOne(instruction); |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3833 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3834 | if (is_div) { |
| 3835 | DivByPowerOfTwo(instruction->AsDiv()); |
| 3836 | } else { |
| 3837 | RemByPowerOfTwo(instruction->AsRem()); |
| 3838 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3839 | } else { |
| 3840 | DCHECK(imm <= -2 || imm >= 2); |
| 3841 | GenerateDivRemWithAnyConstant(instruction); |
| 3842 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3843 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3844 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3845 | new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3846 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3847 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3848 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3849 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3850 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3851 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3852 | // 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] | 3853 | if (type == DataType::Type::kInt32) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3854 | __ cmpl(second_reg, Immediate(-1)); |
| 3855 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3856 | // edx:eax <- sign-extended of eax |
| 3857 | __ cdq(); |
| 3858 | // eax = quotient, edx = remainder |
| 3859 | __ idivl(second_reg); |
| 3860 | } else { |
| 3861 | __ cmpq(second_reg, Immediate(-1)); |
| 3862 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3863 | // rdx:rax <- sign-extended of rax |
| 3864 | __ cqo(); |
| 3865 | // rax = quotient, rdx = remainder |
| 3866 | __ idivq(second_reg); |
| 3867 | } |
| 3868 | __ Bind(slow_path->GetExitLabel()); |
| 3869 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3870 | } |
| 3871 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3872 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3873 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3874 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3875 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3876 | case DataType::Type::kInt32: |
| 3877 | case DataType::Type::kInt64: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3878 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3879 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3880 | locations->SetOut(Location::SameAsFirstInput()); |
| 3881 | // Intel uses edx:eax as the dividend. |
| 3882 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3883 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3884 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3885 | // output and request another temp. |
| 3886 | if (div->InputAt(1)->IsConstant()) { |
| 3887 | locations->AddTemp(Location::RequiresRegister()); |
| 3888 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3889 | break; |
| 3890 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3891 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3892 | case DataType::Type::kFloat32: |
| 3893 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3894 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3895 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3896 | locations->SetOut(Location::SameAsFirstInput()); |
| 3897 | break; |
| 3898 | } |
| 3899 | |
| 3900 | default: |
| 3901 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3902 | } |
| 3903 | } |
| 3904 | |
| 3905 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3906 | LocationSummary* locations = div->GetLocations(); |
| 3907 | Location first = locations->InAt(0); |
| 3908 | Location second = locations->InAt(1); |
| 3909 | DCHECK(first.Equals(locations->Out())); |
| 3910 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3911 | DataType::Type type = div->GetResultType(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3912 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3913 | case DataType::Type::kInt32: |
| 3914 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3915 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3916 | break; |
| 3917 | } |
| 3918 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3919 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3920 | if (second.IsFpuRegister()) { |
| 3921 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3922 | } else if (second.IsConstant()) { |
| 3923 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3924 | codegen_->LiteralFloatAddress( |
| 3925 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3926 | } else { |
| 3927 | DCHECK(second.IsStackSlot()); |
| 3928 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3929 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3930 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3931 | break; |
| 3932 | } |
| 3933 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3934 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3935 | if (second.IsFpuRegister()) { |
| 3936 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3937 | } else if (second.IsConstant()) { |
| 3938 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3939 | codegen_->LiteralDoubleAddress( |
| 3940 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3941 | } else { |
| 3942 | DCHECK(second.IsDoubleStackSlot()); |
| 3943 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3944 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3945 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3946 | break; |
| 3947 | } |
| 3948 | |
| 3949 | default: |
| 3950 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3951 | } |
| 3952 | } |
| 3953 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3954 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3955 | DataType::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3956 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3957 | new (GetGraph()->GetAllocator()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3958 | |
| 3959 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3960 | case DataType::Type::kInt32: |
| 3961 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3962 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3963 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3964 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3965 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3966 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3967 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3968 | // output and request another temp. |
| 3969 | if (rem->InputAt(1)->IsConstant()) { |
| 3970 | locations->AddTemp(Location::RequiresRegister()); |
| 3971 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3972 | break; |
| 3973 | } |
| 3974 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3975 | case DataType::Type::kFloat32: |
| 3976 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3977 | locations->SetInAt(0, Location::Any()); |
| 3978 | locations->SetInAt(1, Location::Any()); |
| 3979 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3980 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3981 | break; |
| 3982 | } |
| 3983 | |
| 3984 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3985 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3986 | } |
| 3987 | } |
| 3988 | |
| 3989 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3990 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3991 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3992 | case DataType::Type::kInt32: |
| 3993 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3994 | GenerateDivRemIntegral(rem); |
| 3995 | break; |
| 3996 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3997 | case DataType::Type::kFloat32: |
| 3998 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3999 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 4000 | break; |
| 4001 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4002 | default: |
| 4003 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 4004 | } |
| 4005 | } |
| 4006 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4007 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4008 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4009 | switch (minmax->GetResultType()) { |
| 4010 | case DataType::Type::kInt32: |
| 4011 | case DataType::Type::kInt64: |
| 4012 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4013 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4014 | locations->SetOut(Location::SameAsFirstInput()); |
| 4015 | break; |
| 4016 | case DataType::Type::kFloat32: |
| 4017 | case DataType::Type::kFloat64: |
| 4018 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4019 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4020 | // The following is sub-optimal, but all we can do for now. It would be fine to also accept |
| 4021 | // the second input to be the output (we can simply swap inputs). |
| 4022 | locations->SetOut(Location::SameAsFirstInput()); |
| 4023 | break; |
| 4024 | default: |
| 4025 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4026 | } |
| 4027 | } |
| 4028 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4029 | void InstructionCodeGeneratorX86_64::GenerateMinMaxInt(LocationSummary* locations, |
| 4030 | bool is_min, |
| 4031 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4032 | Location op1_loc = locations->InAt(0); |
| 4033 | Location op2_loc = locations->InAt(1); |
| 4034 | |
| 4035 | // Shortcut for same input locations. |
| 4036 | if (op1_loc.Equals(op2_loc)) { |
| 4037 | // Can return immediately, as op1_loc == out_loc. |
| 4038 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 4039 | // a copy here. |
| 4040 | DCHECK(locations->Out().Equals(op1_loc)); |
| 4041 | return; |
| 4042 | } |
| 4043 | |
| 4044 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4045 | CpuRegister op2 = op2_loc.AsRegister<CpuRegister>(); |
| 4046 | |
| 4047 | // (out := op1) |
| 4048 | // out <=? op2 |
| 4049 | // if out is min jmp done |
| 4050 | // out := op2 |
| 4051 | // done: |
| 4052 | |
| 4053 | if (type == DataType::Type::kInt64) { |
| 4054 | __ cmpq(out, op2); |
| 4055 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ true); |
| 4056 | } else { |
| 4057 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 4058 | __ cmpl(out, op2); |
| 4059 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ false); |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | void InstructionCodeGeneratorX86_64::GenerateMinMaxFP(LocationSummary* locations, |
| 4064 | bool is_min, |
| 4065 | DataType::Type type) { |
| 4066 | Location op1_loc = locations->InAt(0); |
| 4067 | Location op2_loc = locations->InAt(1); |
| 4068 | Location out_loc = locations->Out(); |
| 4069 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4070 | |
| 4071 | // Shortcut for same input locations. |
| 4072 | if (op1_loc.Equals(op2_loc)) { |
| 4073 | DCHECK(out_loc.Equals(op1_loc)); |
| 4074 | return; |
| 4075 | } |
| 4076 | |
| 4077 | // (out := op1) |
| 4078 | // out <=? op2 |
| 4079 | // if Nan jmp Nan_label |
| 4080 | // if out is min jmp done |
| 4081 | // if op2 is min jmp op2_label |
| 4082 | // handle -0/+0 |
| 4083 | // jmp done |
| 4084 | // Nan_label: |
| 4085 | // out := NaN |
| 4086 | // op2_label: |
| 4087 | // out := op2 |
| 4088 | // done: |
| 4089 | // |
| 4090 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4091 | // |
| 4092 | // TODO: This is straight from Quick. Make NaN an out-of-line slowpath? |
| 4093 | |
| 4094 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4095 | |
| 4096 | NearLabel nan, done, op2_label; |
| 4097 | if (type == DataType::Type::kFloat64) { |
| 4098 | __ ucomisd(out, op2); |
| 4099 | } else { |
| 4100 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4101 | __ ucomiss(out, op2); |
| 4102 | } |
| 4103 | |
| 4104 | __ j(Condition::kParityEven, &nan); |
| 4105 | |
| 4106 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4107 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4108 | |
| 4109 | // Handle 0.0/-0.0. |
| 4110 | if (is_min) { |
| 4111 | if (type == DataType::Type::kFloat64) { |
| 4112 | __ orpd(out, op2); |
| 4113 | } else { |
| 4114 | __ orps(out, op2); |
| 4115 | } |
| 4116 | } else { |
| 4117 | if (type == DataType::Type::kFloat64) { |
| 4118 | __ andpd(out, op2); |
| 4119 | } else { |
| 4120 | __ andps(out, op2); |
| 4121 | } |
| 4122 | } |
| 4123 | __ jmp(&done); |
| 4124 | |
| 4125 | // NaN handling. |
| 4126 | __ Bind(&nan); |
| 4127 | if (type == DataType::Type::kFloat64) { |
| 4128 | __ movsd(out, codegen_->LiteralInt64Address(INT64_C(0x7FF8000000000000))); |
| 4129 | } else { |
| 4130 | __ movss(out, codegen_->LiteralInt32Address(INT32_C(0x7FC00000))); |
| 4131 | } |
| 4132 | __ jmp(&done); |
| 4133 | |
| 4134 | // out := op2; |
| 4135 | __ Bind(&op2_label); |
| 4136 | if (type == DataType::Type::kFloat64) { |
| 4137 | __ movsd(out, op2); |
| 4138 | } else { |
| 4139 | __ movss(out, op2); |
| 4140 | } |
| 4141 | |
| 4142 | // Done. |
| 4143 | __ Bind(&done); |
| 4144 | } |
| 4145 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4146 | void InstructionCodeGeneratorX86_64::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4147 | DataType::Type type = minmax->GetResultType(); |
| 4148 | switch (type) { |
| 4149 | case DataType::Type::kInt32: |
| 4150 | case DataType::Type::kInt64: |
| 4151 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4152 | break; |
| 4153 | case DataType::Type::kFloat32: |
| 4154 | case DataType::Type::kFloat64: |
| 4155 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4156 | break; |
| 4157 | default: |
| 4158 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4159 | } |
| 4160 | } |
| 4161 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4162 | void LocationsBuilderX86_64::VisitMin(HMin* min) { |
| 4163 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4164 | } |
| 4165 | |
| 4166 | void InstructionCodeGeneratorX86_64::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4167 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | void LocationsBuilderX86_64::VisitMax(HMax* max) { |
| 4171 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4172 | } |
| 4173 | |
| 4174 | void InstructionCodeGeneratorX86_64::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4175 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4176 | } |
| 4177 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4178 | void LocationsBuilderX86_64::VisitAbs(HAbs* abs) { |
| 4179 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4180 | switch (abs->GetResultType()) { |
| 4181 | case DataType::Type::kInt32: |
| 4182 | case DataType::Type::kInt64: |
| 4183 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4184 | locations->SetOut(Location::SameAsFirstInput()); |
| 4185 | locations->AddTemp(Location::RequiresRegister()); |
| 4186 | break; |
| 4187 | case DataType::Type::kFloat32: |
| 4188 | case DataType::Type::kFloat64: |
| 4189 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4190 | locations->SetOut(Location::SameAsFirstInput()); |
| 4191 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4192 | break; |
| 4193 | default: |
| 4194 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4195 | } |
| 4196 | } |
| 4197 | |
| 4198 | void InstructionCodeGeneratorX86_64::VisitAbs(HAbs* abs) { |
| 4199 | LocationSummary* locations = abs->GetLocations(); |
| 4200 | switch (abs->GetResultType()) { |
| 4201 | case DataType::Type::kInt32: { |
| 4202 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4203 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4204 | // Create mask. |
| 4205 | __ movl(mask, out); |
| 4206 | __ sarl(mask, Immediate(31)); |
| 4207 | // Add mask. |
| 4208 | __ addl(out, mask); |
| 4209 | __ xorl(out, mask); |
| 4210 | break; |
| 4211 | } |
| 4212 | case DataType::Type::kInt64: { |
| 4213 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4214 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4215 | // Create mask. |
| 4216 | __ movq(mask, out); |
| 4217 | __ sarq(mask, Immediate(63)); |
| 4218 | // Add mask. |
| 4219 | __ addq(out, mask); |
| 4220 | __ xorq(out, mask); |
| 4221 | break; |
| 4222 | } |
| 4223 | case DataType::Type::kFloat32: { |
| 4224 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4225 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4226 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x7FFFFFFF))); |
| 4227 | __ andps(out, mask); |
| 4228 | break; |
| 4229 | } |
| 4230 | case DataType::Type::kFloat64: { |
| 4231 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4232 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4233 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x7FFFFFFFFFFFFFFF))); |
| 4234 | __ andpd(out, mask); |
| 4235 | break; |
| 4236 | } |
| 4237 | default: |
| 4238 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4239 | } |
| 4240 | } |
| 4241 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4242 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4243 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4244 | locations->SetInAt(0, Location::Any()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4245 | } |
| 4246 | |
| 4247 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4248 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4249 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86_64(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4250 | codegen_->AddSlowPath(slow_path); |
| 4251 | |
| 4252 | LocationSummary* locations = instruction->GetLocations(); |
| 4253 | Location value = locations->InAt(0); |
| 4254 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4255 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4256 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4257 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4258 | case DataType::Type::kInt8: |
| 4259 | case DataType::Type::kUint16: |
| 4260 | case DataType::Type::kInt16: |
| 4261 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4262 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4263 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4264 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4265 | } else if (value.IsStackSlot()) { |
| 4266 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4267 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4268 | } else { |
| 4269 | DCHECK(value.IsConstant()) << value; |
| 4270 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4271 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4272 | } |
| 4273 | } |
| 4274 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4275 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4276 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4277 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4278 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4279 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4280 | } else if (value.IsDoubleStackSlot()) { |
| 4281 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4282 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4283 | } else { |
| 4284 | DCHECK(value.IsConstant()) << value; |
| 4285 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4286 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4287 | } |
| 4288 | } |
| 4289 | break; |
| 4290 | } |
| 4291 | default: |
| 4292 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4293 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4294 | } |
| 4295 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4296 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 4297 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4298 | |
| 4299 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4300 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4301 | |
| 4302 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4303 | case DataType::Type::kInt32: |
| 4304 | case DataType::Type::kInt64: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4305 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4306 | // The shift count needs to be in CL. |
| 4307 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 4308 | locations->SetOut(Location::SameAsFirstInput()); |
| 4309 | break; |
| 4310 | } |
| 4311 | default: |
| 4312 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4313 | } |
| 4314 | } |
| 4315 | |
| 4316 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 4317 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4318 | |
| 4319 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4320 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4321 | Location second = locations->InAt(1); |
| 4322 | |
| 4323 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4324 | case DataType::Type::kInt32: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4325 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4326 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4327 | if (op->IsShl()) { |
| 4328 | __ shll(first_reg, second_reg); |
| 4329 | } else if (op->IsShr()) { |
| 4330 | __ sarl(first_reg, second_reg); |
| 4331 | } else { |
| 4332 | __ shrl(first_reg, second_reg); |
| 4333 | } |
| 4334 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4335 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4336 | if (op->IsShl()) { |
| 4337 | __ shll(first_reg, imm); |
| 4338 | } else if (op->IsShr()) { |
| 4339 | __ sarl(first_reg, imm); |
| 4340 | } else { |
| 4341 | __ shrl(first_reg, imm); |
| 4342 | } |
| 4343 | } |
| 4344 | break; |
| 4345 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4346 | case DataType::Type::kInt64: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4347 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4348 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4349 | if (op->IsShl()) { |
| 4350 | __ shlq(first_reg, second_reg); |
| 4351 | } else if (op->IsShr()) { |
| 4352 | __ sarq(first_reg, second_reg); |
| 4353 | } else { |
| 4354 | __ shrq(first_reg, second_reg); |
| 4355 | } |
| 4356 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4357 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4358 | if (op->IsShl()) { |
| 4359 | __ shlq(first_reg, imm); |
| 4360 | } else if (op->IsShr()) { |
| 4361 | __ sarq(first_reg, imm); |
| 4362 | } else { |
| 4363 | __ shrq(first_reg, imm); |
| 4364 | } |
| 4365 | } |
| 4366 | break; |
| 4367 | } |
| 4368 | default: |
| 4369 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4370 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4371 | } |
| 4372 | } |
| 4373 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4374 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 4375 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4376 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4377 | |
| 4378 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4379 | case DataType::Type::kInt32: |
| 4380 | case DataType::Type::kInt64: { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4381 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4382 | // The shift count needs to be in CL (unless it is a constant). |
| 4383 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 4384 | locations->SetOut(Location::SameAsFirstInput()); |
| 4385 | break; |
| 4386 | } |
| 4387 | default: |
| 4388 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4389 | UNREACHABLE(); |
| 4390 | } |
| 4391 | } |
| 4392 | |
| 4393 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4394 | LocationSummary* locations = ror->GetLocations(); |
| 4395 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4396 | Location second = locations->InAt(1); |
| 4397 | |
| 4398 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4399 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4400 | if (second.IsRegister()) { |
| 4401 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4402 | __ rorl(first_reg, second_reg); |
| 4403 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4404 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4405 | __ rorl(first_reg, imm); |
| 4406 | } |
| 4407 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4408 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4409 | if (second.IsRegister()) { |
| 4410 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4411 | __ rorq(first_reg, second_reg); |
| 4412 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4413 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4414 | __ rorq(first_reg, imm); |
| 4415 | } |
| 4416 | break; |
| 4417 | default: |
| 4418 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4419 | UNREACHABLE(); |
| 4420 | } |
| 4421 | } |
| 4422 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4423 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4424 | HandleShift(shl); |
| 4425 | } |
| 4426 | |
| 4427 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4428 | HandleShift(shl); |
| 4429 | } |
| 4430 | |
| 4431 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4432 | HandleShift(shr); |
| 4433 | } |
| 4434 | |
| 4435 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4436 | HandleShift(shr); |
| 4437 | } |
| 4438 | |
| 4439 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4440 | HandleShift(ushr); |
| 4441 | } |
| 4442 | |
| 4443 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4444 | HandleShift(ushr); |
| 4445 | } |
| 4446 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4447 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4448 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4449 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4450 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4451 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4452 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4453 | } |
| 4454 | |
| 4455 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4456 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4457 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4458 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4459 | } |
| 4460 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4461 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4462 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4463 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4464 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4465 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4466 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4467 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4468 | } |
| 4469 | |
| 4470 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4471 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 4472 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4473 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4474 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4475 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4476 | } |
| 4477 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4478 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4479 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4480 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4481 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4482 | if (location.IsStackSlot()) { |
| 4483 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4484 | } else if (location.IsDoubleStackSlot()) { |
| 4485 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4486 | } |
| 4487 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4488 | } |
| 4489 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4490 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4491 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4492 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4496 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4497 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4498 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4499 | } |
| 4500 | |
| 4501 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4502 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4503 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4504 | } |
| 4505 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4506 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4507 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4508 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4509 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4510 | locations->SetOut(Location::RequiresRegister()); |
| 4511 | } |
| 4512 | |
| 4513 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4514 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4515 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4516 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4517 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4518 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4519 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4520 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4521 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4522 | instruction->GetIndex(), kX86_64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4523 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4524 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4525 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4526 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4527 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4528 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4529 | } |
| 4530 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4531 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4532 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4533 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4534 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4535 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4536 | } |
| 4537 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4538 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4539 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4540 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4541 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4542 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4543 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4544 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4545 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4546 | break; |
| 4547 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4548 | case DataType::Type::kInt64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4549 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4550 | break; |
| 4551 | |
| 4552 | default: |
| 4553 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4554 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4555 | } |
| 4556 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4557 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4558 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4559 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4560 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4561 | locations->SetOut(Location::SameAsFirstInput()); |
| 4562 | } |
| 4563 | |
| 4564 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4565 | LocationSummary* locations = bool_not->GetLocations(); |
| 4566 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4567 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4568 | Location out = locations->Out(); |
| 4569 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4570 | } |
| 4571 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4572 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4573 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4574 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4575 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4576 | locations->SetInAt(i, Location::Any()); |
| 4577 | } |
| 4578 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4579 | } |
| 4580 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4581 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4582 | LOG(FATAL) << "Unimplemented"; |
| 4583 | } |
| 4584 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4585 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4586 | /* |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4587 | * 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] | 4588 | * 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] | 4589 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4590 | */ |
| 4591 | switch (kind) { |
| 4592 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4593 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4594 | break; |
| 4595 | } |
| 4596 | case MemBarrierKind::kAnyStore: |
| 4597 | case MemBarrierKind::kLoadAny: |
| 4598 | case MemBarrierKind::kStoreStore: { |
| 4599 | // nop |
| 4600 | break; |
| 4601 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4602 | case MemBarrierKind::kNTStoreStore: |
| 4603 | // Non-Temporal Store/Store needs an explicit fence. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4604 | MemoryFence(/* non-temporal= */ true); |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4605 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4606 | } |
| 4607 | } |
| 4608 | |
| 4609 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4610 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4611 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4612 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4613 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4614 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4615 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4616 | object_field_get_with_read_barrier |
| 4617 | ? LocationSummary::kCallOnSlowPath |
| 4618 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4619 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4620 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4621 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4622 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4623 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4624 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4625 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4626 | // The output overlaps for an object field get when read barriers |
| 4627 | // are enabled: we do not want the move to overwrite the object's |
| 4628 | // location, as we need it to emit the read barrier. |
| 4629 | locations->SetOut( |
| 4630 | Location::RequiresRegister(), |
| 4631 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4632 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4636 | const FieldInfo& field_info) { |
| 4637 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4638 | |
| 4639 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4640 | Location base_loc = locations->InAt(0); |
| 4641 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4642 | Location out = locations->Out(); |
| 4643 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4644 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4645 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4646 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4647 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4648 | switch (load_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4649 | case DataType::Type::kBool: |
| 4650 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4651 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4652 | break; |
| 4653 | } |
| 4654 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4655 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4656 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4657 | break; |
| 4658 | } |
| 4659 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4660 | case DataType::Type::kUint16: { |
| 4661 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4662 | break; |
| 4663 | } |
| 4664 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4665 | case DataType::Type::kInt16: { |
| 4666 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4667 | break; |
| 4668 | } |
| 4669 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4670 | case DataType::Type::kInt32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4671 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4672 | break; |
| 4673 | } |
| 4674 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4675 | case DataType::Type::kReference: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4676 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4677 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4678 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4679 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4680 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4681 | instruction, out, base, offset, /* needs_null_check= */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4682 | if (is_volatile) { |
| 4683 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4684 | } |
| 4685 | } else { |
| 4686 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4687 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4688 | if (is_volatile) { |
| 4689 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4690 | } |
| 4691 | // If read barriers are enabled, emit read barriers other than |
| 4692 | // Baker's using a slow path (and also unpoison the loaded |
| 4693 | // reference, if heap poisoning is enabled). |
| 4694 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4695 | } |
| 4696 | break; |
| 4697 | } |
| 4698 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4699 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4700 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4701 | break; |
| 4702 | } |
| 4703 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4704 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4705 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4706 | break; |
| 4707 | } |
| 4708 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4709 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4710 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4711 | break; |
| 4712 | } |
| 4713 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4714 | case DataType::Type::kUint32: |
| 4715 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4716 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4717 | LOG(FATAL) << "Unreachable type " << load_type; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4718 | UNREACHABLE(); |
| 4719 | } |
| 4720 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4721 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4722 | // Potential implicit null checks, in the case of reference |
| 4723 | // fields, are handled in the previous switch statement. |
| 4724 | } else { |
| 4725 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4726 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4727 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4728 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4729 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4730 | // Memory barriers, in the case of references, are also handled |
| 4731 | // in the previous switch statement. |
| 4732 | } else { |
| 4733 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4734 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4735 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4739 | const FieldInfo& field_info) { |
| 4740 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4741 | |
| 4742 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4743 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4744 | DataType::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4745 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4746 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4747 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4748 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4749 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4750 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4751 | if (is_volatile) { |
| 4752 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4753 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4754 | } else { |
| 4755 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4756 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4757 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4758 | if (is_volatile) { |
| 4759 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4760 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4761 | } else { |
| 4762 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4763 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4764 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4765 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4766 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4767 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4768 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4769 | } else if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4770 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4771 | locations->AddTemp(Location::RequiresRegister()); |
| 4772 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4773 | } |
| 4774 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4775 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4776 | const FieldInfo& field_info, |
| 4777 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4778 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4779 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4780 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4781 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4782 | Location value = locations->InAt(1); |
| 4783 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4784 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4785 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4786 | |
| 4787 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4788 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4789 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4790 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4791 | bool maybe_record_implicit_null_check_done = false; |
| 4792 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4793 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4794 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4795 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4796 | case DataType::Type::kInt8: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4797 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4798 | __ movb(Address(base, offset), |
| 4799 | Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4800 | } else { |
| 4801 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4802 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4803 | break; |
| 4804 | } |
| 4805 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4806 | case DataType::Type::kUint16: |
| 4807 | case DataType::Type::kInt16: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4808 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4809 | __ movw(Address(base, offset), |
| 4810 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4811 | } else { |
| 4812 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4813 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4814 | break; |
| 4815 | } |
| 4816 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4817 | case DataType::Type::kInt32: |
| 4818 | case DataType::Type::kReference: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4819 | if (value.IsConstant()) { |
| 4820 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4821 | // `field_type == DataType::Type::kReference` implies `v == 0`. |
| 4822 | DCHECK((field_type != DataType::Type::kReference) || (v == 0)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4823 | // Note: if heap poisoning is enabled, no need to poison |
| 4824 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4825 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4826 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4827 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4828 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4829 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4830 | __ PoisonHeapReference(temp); |
| 4831 | __ movl(Address(base, offset), temp); |
| 4832 | } else { |
| 4833 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4834 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4835 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4836 | break; |
| 4837 | } |
| 4838 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4839 | case DataType::Type::kInt64: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4840 | if (value.IsConstant()) { |
| 4841 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4842 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4843 | Address(base, offset + sizeof(int32_t)), |
| 4844 | v, |
| 4845 | instruction); |
| 4846 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4847 | } else { |
| 4848 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4849 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4850 | break; |
| 4851 | } |
| 4852 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4853 | case DataType::Type::kFloat32: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4854 | if (value.IsConstant()) { |
| 4855 | int32_t v = |
| 4856 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4857 | __ movl(Address(base, offset), Immediate(v)); |
| 4858 | } else { |
| 4859 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4860 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4861 | break; |
| 4862 | } |
| 4863 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4864 | case DataType::Type::kFloat64: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4865 | if (value.IsConstant()) { |
| 4866 | int64_t v = |
| 4867 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4868 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4869 | Address(base, offset + sizeof(int32_t)), |
| 4870 | v, |
| 4871 | instruction); |
| 4872 | maybe_record_implicit_null_check_done = true; |
| 4873 | } else { |
| 4874 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4875 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4876 | break; |
| 4877 | } |
| 4878 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4879 | case DataType::Type::kUint32: |
| 4880 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4881 | case DataType::Type::kVoid: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4882 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4883 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4884 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4885 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4886 | if (!maybe_record_implicit_null_check_done) { |
| 4887 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4888 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4889 | |
| 4890 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4891 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4892 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4893 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4894 | } |
| 4895 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4896 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4897 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4898 | } |
| 4899 | } |
| 4900 | |
| 4901 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4902 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4903 | } |
| 4904 | |
| 4905 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4906 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4907 | } |
| 4908 | |
| 4909 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4910 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4914 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4915 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4916 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4917 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4918 | HandleFieldGet(instruction); |
| 4919 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4920 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4921 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4922 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4923 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4924 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4925 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4926 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4927 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4928 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4929 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4930 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4931 | } |
| 4932 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 4933 | void LocationsBuilderX86_64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 4934 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(RAX)); |
| 4935 | } |
| 4936 | |
| 4937 | void InstructionCodeGeneratorX86_64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 4938 | __ movl(CpuRegister(RDI), Immediate(instruction->GetFormat()->GetValue())); |
| 4939 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 4940 | } |
| 4941 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4942 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4943 | HUnresolvedInstanceFieldGet* instruction) { |
| 4944 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4945 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4946 | instruction, instruction->GetFieldType(), calling_convention); |
| 4947 | } |
| 4948 | |
| 4949 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4950 | HUnresolvedInstanceFieldGet* instruction) { |
| 4951 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4952 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4953 | instruction->GetFieldType(), |
| 4954 | instruction->GetFieldIndex(), |
| 4955 | instruction->GetDexPc(), |
| 4956 | calling_convention); |
| 4957 | } |
| 4958 | |
| 4959 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4960 | HUnresolvedInstanceFieldSet* instruction) { |
| 4961 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4962 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4963 | instruction, instruction->GetFieldType(), calling_convention); |
| 4964 | } |
| 4965 | |
| 4966 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4967 | HUnresolvedInstanceFieldSet* instruction) { |
| 4968 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4969 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4970 | instruction->GetFieldType(), |
| 4971 | instruction->GetFieldIndex(), |
| 4972 | instruction->GetDexPc(), |
| 4973 | calling_convention); |
| 4974 | } |
| 4975 | |
| 4976 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4977 | HUnresolvedStaticFieldGet* instruction) { |
| 4978 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4979 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4980 | instruction, instruction->GetFieldType(), calling_convention); |
| 4981 | } |
| 4982 | |
| 4983 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4984 | HUnresolvedStaticFieldGet* instruction) { |
| 4985 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4986 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4987 | instruction->GetFieldType(), |
| 4988 | instruction->GetFieldIndex(), |
| 4989 | instruction->GetDexPc(), |
| 4990 | calling_convention); |
| 4991 | } |
| 4992 | |
| 4993 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4994 | HUnresolvedStaticFieldSet* instruction) { |
| 4995 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4996 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4997 | instruction, instruction->GetFieldType(), calling_convention); |
| 4998 | } |
| 4999 | |
| 5000 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 5001 | HUnresolvedStaticFieldSet* instruction) { |
| 5002 | FieldAccessCallingConventionX86_64 calling_convention; |
| 5003 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5004 | instruction->GetFieldType(), |
| 5005 | instruction->GetFieldIndex(), |
| 5006 | instruction->GetDexPc(), |
| 5007 | calling_convention); |
| 5008 | } |
| 5009 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5010 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5011 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5012 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5013 | ? Location::RequiresRegister() |
| 5014 | : Location::Any(); |
| 5015 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5016 | } |
| 5017 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5018 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5019 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5020 | return; |
| 5021 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5022 | LocationSummary* locations = instruction->GetLocations(); |
| 5023 | Location obj = locations->InAt(0); |
| 5024 | |
| 5025 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5026 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5027 | } |
| 5028 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5029 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5030 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5031 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5032 | |
| 5033 | LocationSummary* locations = instruction->GetLocations(); |
| 5034 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5035 | |
| 5036 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5037 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5038 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5039 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5040 | } else { |
| 5041 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5042 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5043 | __ jmp(slow_path->GetEntryLabel()); |
| 5044 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5045 | } |
| 5046 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5047 | } |
| 5048 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5049 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5050 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5051 | } |
| 5052 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5053 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5054 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5055 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5056 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5057 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5058 | object_array_get_with_read_barrier |
| 5059 | ? LocationSummary::kCallOnSlowPath |
| 5060 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5061 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5062 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5063 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5064 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5065 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5066 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5067 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5068 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5069 | // The output overlaps for an object array get when read barriers |
| 5070 | // are enabled: we do not want the move to overwrite the array's |
| 5071 | // location, as we need it to emit the read barrier. |
| 5072 | locations->SetOut( |
| 5073 | Location::RequiresRegister(), |
| 5074 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5075 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 5079 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5080 | Location obj_loc = locations->InAt(0); |
| 5081 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5082 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5083 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5084 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5085 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5086 | DataType::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5087 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5088 | case DataType::Type::kBool: |
| 5089 | case DataType::Type::kUint8: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5090 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5091 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5092 | break; |
| 5093 | } |
| 5094 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5095 | case DataType::Type::kInt8: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5096 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5097 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5098 | break; |
| 5099 | } |
| 5100 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5101 | case DataType::Type::kUint16: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5102 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5103 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5104 | // Branch cases into compressed and uncompressed for each index's type. |
| 5105 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5106 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5107 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5108 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5109 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5110 | "Expecting 0=compressed, 1=uncompressed"); |
| 5111 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5112 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5113 | __ jmp(&done); |
| 5114 | __ Bind(¬_compressed); |
| 5115 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5116 | __ Bind(&done); |
| 5117 | } else { |
| 5118 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5119 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5120 | break; |
| 5121 | } |
| 5122 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5123 | case DataType::Type::kInt16: { |
| 5124 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 5125 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5126 | break; |
| 5127 | } |
| 5128 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5129 | case DataType::Type::kInt32: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5130 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5131 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5132 | break; |
| 5133 | } |
| 5134 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5135 | case DataType::Type::kReference: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5136 | static_assert( |
| 5137 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5138 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5139 | // /* HeapReference<Object> */ out = |
| 5140 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5141 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5142 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5143 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5144 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5145 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5146 | } else { |
| 5147 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5148 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5149 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5150 | // If read barriers are enabled, emit read barriers other than |
| 5151 | // Baker's using a slow path (and also unpoison the loaded |
| 5152 | // reference, if heap poisoning is enabled). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5153 | if (index.IsConstant()) { |
| 5154 | uint32_t offset = |
| 5155 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5156 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5157 | } else { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5158 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5159 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5160 | } |
| 5161 | } |
| 5162 | break; |
| 5163 | } |
| 5164 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5165 | case DataType::Type::kInt64: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5166 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5167 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5168 | break; |
| 5169 | } |
| 5170 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5171 | case DataType::Type::kFloat32: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5172 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5173 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5174 | break; |
| 5175 | } |
| 5176 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5177 | case DataType::Type::kFloat64: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5178 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5179 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5180 | break; |
| 5181 | } |
| 5182 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5183 | case DataType::Type::kUint32: |
| 5184 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5185 | case DataType::Type::kVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5186 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5187 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5188 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5189 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5190 | if (type == DataType::Type::kReference) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5191 | // Potential implicit null checks, in the case of reference |
| 5192 | // arrays, are handled in the previous switch statement. |
| 5193 | } else { |
| 5194 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5195 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5199 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5200 | |
| 5201 | bool needs_write_barrier = |
| 5202 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5203 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5204 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5205 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5206 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5207 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5208 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5209 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5210 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5211 | if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5212 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5213 | } else { |
| 5214 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5215 | } |
| 5216 | |
| 5217 | if (needs_write_barrier) { |
| 5218 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5219 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5220 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5221 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5222 | } |
| 5223 | |
| 5224 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 5225 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5226 | Location array_loc = locations->InAt(0); |
| 5227 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5228 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5229 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5230 | DataType::Type value_type = instruction->GetComponentType(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5231 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5232 | bool needs_write_barrier = |
| 5233 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5234 | |
| 5235 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5236 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5237 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5238 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5239 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5240 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5241 | if (value.IsRegister()) { |
| 5242 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5243 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5244 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5245 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5246 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5247 | break; |
| 5248 | } |
| 5249 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5250 | case DataType::Type::kUint16: |
| 5251 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5252 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5253 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5254 | if (value.IsRegister()) { |
| 5255 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5256 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5257 | DCHECK(value.IsConstant()) << value; |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5258 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5259 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5260 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5261 | break; |
| 5262 | } |
| 5263 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5264 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5265 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5266 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5267 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5268 | if (!value.IsRegister()) { |
| 5269 | // Just setting null. |
| 5270 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5271 | DCHECK(value.IsConstant()) << value; |
| 5272 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5273 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5274 | DCHECK(!needs_write_barrier); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5275 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5276 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5277 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5278 | |
| 5279 | DCHECK(needs_write_barrier); |
| 5280 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5281 | Location temp_loc = locations->GetTemp(0); |
| 5282 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5283 | |
| 5284 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 5285 | NearLabel do_store; |
| 5286 | if (can_value_be_null) { |
| 5287 | __ testl(register_value, register_value); |
| 5288 | __ j(kEqual, &do_store); |
| 5289 | } |
| 5290 | |
| 5291 | SlowPathCode* slow_path = nullptr; |
| 5292 | if (needs_type_check) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5293 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86_64(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5294 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5295 | |
| 5296 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5297 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5298 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5299 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5300 | // Note that when Baker read barriers are enabled, the type |
| 5301 | // checks are performed without read barriers. This is fine, |
| 5302 | // even in the case where a class object is in the from-space |
| 5303 | // after the flip, as a comparison involving such a type would |
| 5304 | // not produce a false positive; it may of course produce a |
| 5305 | // false negative, in which case we would take the ArraySet |
| 5306 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5307 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5308 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5309 | __ movl(temp, Address(array, class_offset)); |
| 5310 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5311 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5312 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5313 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5314 | __ movl(temp, Address(temp, component_offset)); |
| 5315 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5316 | // nor the object reference in `register_value->klass`, as |
| 5317 | // we are comparing two poisoned references. |
| 5318 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5319 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5320 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5321 | NearLabel do_put; |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5322 | __ j(kEqual, &do_put); |
| 5323 | // If heap poisoning is enabled, the `temp` reference has |
| 5324 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5325 | __ MaybeUnpoisonHeapReference(temp); |
| 5326 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5327 | // If heap poisoning is enabled, no need to unpoison the |
| 5328 | // heap reference loaded below, as it is only used for a |
| 5329 | // comparison with null. |
| 5330 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5331 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5332 | __ Bind(&do_put); |
| 5333 | } else { |
| 5334 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5335 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5336 | } |
| 5337 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5338 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 5339 | codegen_->MarkGCCard( |
| 5340 | temp, card, array, value.AsRegister<CpuRegister>(), /* value_can_be_null= */ false); |
| 5341 | |
| 5342 | if (can_value_be_null) { |
| 5343 | DCHECK(do_store.IsLinked()); |
| 5344 | __ Bind(&do_store); |
| 5345 | } |
| 5346 | |
| 5347 | Location source = value; |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5348 | if (kPoisonHeapReferences) { |
| 5349 | __ movl(temp, register_value); |
| 5350 | __ PoisonHeapReference(temp); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5351 | source = temp_loc; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5352 | } |
| 5353 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5354 | __ movl(address, source.AsRegister<CpuRegister>()); |
| 5355 | |
| 5356 | if (can_value_be_null || !needs_type_check) { |
| 5357 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5358 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5359 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5360 | if (slow_path != nullptr) { |
| 5361 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5362 | } |
| 5363 | |
| 5364 | break; |
| 5365 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5366 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5367 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5368 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5369 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5370 | if (value.IsRegister()) { |
| 5371 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 5372 | } else { |
| 5373 | DCHECK(value.IsConstant()) << value; |
| 5374 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5375 | __ movl(address, Immediate(v)); |
| 5376 | } |
| 5377 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5378 | break; |
| 5379 | } |
| 5380 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5381 | case DataType::Type::kInt64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5382 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5383 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5384 | if (value.IsRegister()) { |
| 5385 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5386 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5387 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5388 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5389 | Address address_high = |
| 5390 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5391 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5392 | } |
| 5393 | break; |
| 5394 | } |
| 5395 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5396 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5397 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5398 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5399 | if (value.IsFpuRegister()) { |
| 5400 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5401 | } else { |
| 5402 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5403 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5404 | __ movl(address, Immediate(v)); |
| 5405 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5406 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5407 | break; |
| 5408 | } |
| 5409 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5410 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5411 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5412 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5413 | if (value.IsFpuRegister()) { |
| 5414 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5415 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5416 | } else { |
| 5417 | int64_t v = |
| 5418 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5419 | Address address_high = |
| 5420 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5421 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5422 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5423 | break; |
| 5424 | } |
| 5425 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5426 | case DataType::Type::kUint32: |
| 5427 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5428 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5429 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5430 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5431 | } |
| 5432 | } |
| 5433 | |
| 5434 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5435 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5436 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5437 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5438 | if (!instruction->IsEmittedAtUseSite()) { |
| 5439 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5440 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5441 | } |
| 5442 | |
| 5443 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5444 | if (instruction->IsEmittedAtUseSite()) { |
| 5445 | return; |
| 5446 | } |
| 5447 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5448 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5449 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5450 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5451 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5452 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5453 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5454 | // Mask out most significant bit in case the array is String's array of char. |
| 5455 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5456 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5457 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5458 | } |
| 5459 | |
| 5460 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5461 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5462 | InvokeRuntimeCallingConvention calling_convention; |
| 5463 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5464 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5465 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5466 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5467 | HInstruction* length = instruction->InputAt(1); |
| 5468 | if (!length->IsEmittedAtUseSite()) { |
| 5469 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5470 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5471 | } |
| 5472 | |
| 5473 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5474 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5475 | Location index_loc = locations->InAt(0); |
| 5476 | Location length_loc = locations->InAt(1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5477 | SlowPathCode* slow_path = |
| 5478 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5479 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5480 | if (length_loc.IsConstant()) { |
| 5481 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5482 | if (index_loc.IsConstant()) { |
| 5483 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5484 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5485 | if (index < 0 || index >= length) { |
| 5486 | codegen_->AddSlowPath(slow_path); |
| 5487 | __ jmp(slow_path->GetEntryLabel()); |
| 5488 | } else { |
| 5489 | // Some optimization after BCE may have generated this, and we should not |
| 5490 | // generate a bounds check if it is a valid range. |
| 5491 | } |
| 5492 | return; |
| 5493 | } |
| 5494 | |
| 5495 | // We have to reverse the jump condition because the length is the constant. |
| 5496 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5497 | __ cmpl(index_reg, Immediate(length)); |
| 5498 | codegen_->AddSlowPath(slow_path); |
| 5499 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5500 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5501 | HInstruction* array_length = instruction->InputAt(1); |
| 5502 | if (array_length->IsEmittedAtUseSite()) { |
| 5503 | // Address the length field in the array. |
| 5504 | DCHECK(array_length->IsArrayLength()); |
| 5505 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5506 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5507 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5508 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5509 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5510 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5511 | CpuRegister length_reg = CpuRegister(TMP); |
| 5512 | __ movl(length_reg, array_len); |
| 5513 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5514 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5515 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5516 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5517 | // Checking the bound for general case: |
| 5518 | // Array of char or String's array when the compression feature off. |
| 5519 | if (index_loc.IsConstant()) { |
| 5520 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5521 | __ cmpl(array_len, Immediate(value)); |
| 5522 | } else { |
| 5523 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5524 | } |
| 5525 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5526 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5527 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5528 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5529 | } |
| 5530 | codegen_->AddSlowPath(slow_path); |
| 5531 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5532 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5533 | } |
| 5534 | |
| 5535 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5536 | CpuRegister card, |
| 5537 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5538 | CpuRegister value, |
| 5539 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5540 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5541 | if (value_can_be_null) { |
| 5542 | __ testl(value, value); |
| 5543 | __ j(kEqual, &is_null); |
| 5544 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5545 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5546 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5547 | /* no_rip= */ true)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5548 | // Calculate the offset (in the card table) of the card corresponding to |
| 5549 | // `object`. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5550 | __ movq(temp, object); |
| 5551 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5552 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5553 | // `object`'s card. |
| 5554 | // |
| 5555 | // Register `card` contains the address of the card table. Note that the card |
| 5556 | // table's base is biased during its creation so that it always starts at an |
| 5557 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5558 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5559 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5560 | // (located at `card + object >> kCardShift`). |
| 5561 | // |
| 5562 | // This dual use of the value in register `card` (1. to calculate the location |
| 5563 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5564 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5565 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5566 | if (value_can_be_null) { |
| 5567 | __ Bind(&is_null); |
| 5568 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5569 | } |
| 5570 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5571 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5572 | LOG(FATAL) << "Unimplemented"; |
| 5573 | } |
| 5574 | |
| 5575 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5576 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5577 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5578 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5579 | // The back edge will generate the suspend check. |
| 5580 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5581 | } |
| 5582 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5583 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5584 | } |
| 5585 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5586 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5587 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5588 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5589 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5590 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5591 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5592 | locations->SetCustomSlowPathCallerSaves( |
| 5593 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5594 | } |
| 5595 | |
| 5596 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5597 | HBasicBlock* block = instruction->GetBlock(); |
| 5598 | if (block->GetLoopInformation() != nullptr) { |
| 5599 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5600 | // The back edge will generate the suspend check. |
| 5601 | return; |
| 5602 | } |
| 5603 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5604 | // The goto will generate the suspend check. |
| 5605 | return; |
| 5606 | } |
| 5607 | GenerateSuspendCheck(instruction, nullptr); |
| 5608 | } |
| 5609 | |
| 5610 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5611 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5612 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5613 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5614 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5615 | slow_path = |
| 5616 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86_64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5617 | instruction->SetSlowPath(slow_path); |
| 5618 | codegen_->AddSlowPath(slow_path); |
| 5619 | if (successor != nullptr) { |
| 5620 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5621 | } |
| 5622 | } else { |
| 5623 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5624 | } |
| 5625 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5626 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5627 | /* no_rip= */ true), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5628 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5629 | if (successor == nullptr) { |
| 5630 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5631 | __ Bind(slow_path->GetReturnLabel()); |
| 5632 | } else { |
| 5633 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5634 | __ jmp(slow_path->GetEntryLabel()); |
| 5635 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5636 | } |
| 5637 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5638 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5639 | return codegen_->GetAssembler(); |
| 5640 | } |
| 5641 | |
| 5642 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5643 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5644 | Location source = move->GetSource(); |
| 5645 | Location destination = move->GetDestination(); |
| 5646 | |
| 5647 | if (source.IsRegister()) { |
| 5648 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5649 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5650 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5651 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5652 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5653 | } else { |
| 5654 | DCHECK(destination.IsDoubleStackSlot()); |
| 5655 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5656 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5657 | } |
| 5658 | } else if (source.IsStackSlot()) { |
| 5659 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5660 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5661 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5662 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5663 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5664 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5665 | } else { |
| 5666 | DCHECK(destination.IsStackSlot()); |
| 5667 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5668 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5669 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5670 | } else if (source.IsDoubleStackSlot()) { |
| 5671 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5672 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5673 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5674 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5675 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5676 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5677 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5678 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5679 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5680 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5681 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5682 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5683 | if (destination.IsFpuRegister()) { |
| 5684 | __ movups(destination.AsFpuRegister<XmmRegister>(), |
| 5685 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5686 | } else { |
| 5687 | DCHECK(destination.IsSIMDStackSlot()); |
| 5688 | size_t high = kX86_64WordSize; |
| 5689 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5690 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5691 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex() + high)); |
| 5692 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex() + high), CpuRegister(TMP)); |
| 5693 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5694 | } else if (source.IsConstant()) { |
| 5695 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5696 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5697 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5698 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5699 | if (value == 0) { |
| 5700 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5701 | } else { |
| 5702 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5703 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5704 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5705 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5706 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5707 | } |
| 5708 | } else if (constant->IsLongConstant()) { |
| 5709 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5710 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5711 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5712 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5713 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5714 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5715 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5716 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5717 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5718 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5719 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5720 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5721 | } else { |
| 5722 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5723 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5724 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5725 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5726 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5727 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5728 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5729 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5730 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5731 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5732 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5733 | } else { |
| 5734 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5735 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5736 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5737 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5738 | } else if (source.IsFpuRegister()) { |
| 5739 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5740 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5741 | } else if (destination.IsStackSlot()) { |
| 5742 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5743 | source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5744 | } else if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5745 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5746 | source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5747 | } else { |
| 5748 | DCHECK(destination.IsSIMDStackSlot()); |
| 5749 | __ movups(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 5750 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5751 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5752 | } |
| 5753 | } |
| 5754 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5755 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5756 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5757 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5758 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5759 | } |
| 5760 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5761 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5762 | __ movq(CpuRegister(TMP), reg1); |
| 5763 | __ movq(reg1, reg2); |
| 5764 | __ movq(reg2, CpuRegister(TMP)); |
| 5765 | } |
| 5766 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5767 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5768 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5769 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5770 | __ movq(reg, CpuRegister(TMP)); |
| 5771 | } |
| 5772 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5773 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5774 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5775 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5776 | __ movd(reg, CpuRegister(TMP)); |
| 5777 | } |
| 5778 | |
| 5779 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5780 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5781 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5782 | __ movd(reg, CpuRegister(TMP)); |
| 5783 | } |
| 5784 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5785 | void ParallelMoveResolverX86_64::Exchange128(XmmRegister reg, int mem) { |
| 5786 | size_t extra_slot = 2 * kX86_64WordSize; |
| 5787 | __ subq(CpuRegister(RSP), Immediate(extra_slot)); |
| 5788 | __ movups(Address(CpuRegister(RSP), 0), XmmRegister(reg)); |
| 5789 | ExchangeMemory64(0, mem + extra_slot, 2); |
| 5790 | __ movups(XmmRegister(reg), Address(CpuRegister(RSP), 0)); |
| 5791 | __ addq(CpuRegister(RSP), Immediate(extra_slot)); |
| 5792 | } |
| 5793 | |
| 5794 | void ParallelMoveResolverX86_64::ExchangeMemory32(int mem1, int mem2) { |
| 5795 | ScratchRegisterScope ensure_scratch( |
| 5796 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5797 | |
| 5798 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5799 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5800 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5801 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5802 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5803 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5804 | CpuRegister(ensure_scratch.GetRegister())); |
| 5805 | } |
| 5806 | |
| 5807 | void ParallelMoveResolverX86_64::ExchangeMemory64(int mem1, int mem2, int num_of_qwords) { |
| 5808 | ScratchRegisterScope ensure_scratch( |
| 5809 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5810 | |
| 5811 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5812 | |
| 5813 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 5814 | for (int i = 0; i < num_of_qwords; i++) { |
| 5815 | __ movq(CpuRegister(TMP), |
| 5816 | Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5817 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5818 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5819 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), |
| 5820 | CpuRegister(TMP)); |
| 5821 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5822 | CpuRegister(ensure_scratch.GetRegister())); |
| 5823 | stack_offset += kX86_64WordSize; |
| 5824 | } |
| 5825 | } |
| 5826 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5827 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5828 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5829 | Location source = move->GetSource(); |
| 5830 | Location destination = move->GetDestination(); |
| 5831 | |
| 5832 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5833 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5834 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5835 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5836 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5837 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5838 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5839 | ExchangeMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5840 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5841 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5842 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5843 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5844 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5845 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5846 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5847 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5848 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5849 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5850 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5851 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5852 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5853 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5854 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5855 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5856 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5857 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5858 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 5859 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 5860 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 5861 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5862 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 5863 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5864 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5865 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5866 | } |
| 5867 | } |
| 5868 | |
| 5869 | |
| 5870 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5871 | __ pushq(CpuRegister(reg)); |
| 5872 | } |
| 5873 | |
| 5874 | |
| 5875 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5876 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5877 | } |
| 5878 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5879 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5880 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 5881 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 5882 | const size_t status_byte_offset = |
| 5883 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 5884 | constexpr uint32_t shifted_visibly_initialized_value = |
| 5885 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 5886 | |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 5887 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 5888 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5889 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5890 | } |
| 5891 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5892 | void InstructionCodeGeneratorX86_64::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 5893 | CpuRegister temp) { |
| 5894 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 5895 | uint32_t mask = check->GetBitstringMask(); |
| 5896 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 5897 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 5898 | |
| 5899 | if (mask_bits == 16u) { |
| 5900 | // Compare the bitstring in memory. |
| 5901 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 5902 | } else { |
| 5903 | // /* uint32_t */ temp = temp->status_ |
| 5904 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 5905 | // Compare the bitstring bits using SUB. |
| 5906 | __ subl(temp, Immediate(path_to_root)); |
| 5907 | // Shift out bits that do not contribute to the comparison. |
| 5908 | __ shll(temp, Immediate(32u - mask_bits)); |
| 5909 | } |
| 5910 | } |
| 5911 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5912 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5913 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5914 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5915 | case HLoadClass::LoadKind::kInvalid: |
| 5916 | LOG(FATAL) << "UNREACHABLE"; |
| 5917 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5918 | case HLoadClass::LoadKind::kReferrersClass: |
| 5919 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5920 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5921 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5922 | case HLoadClass::LoadKind::kBssEntry: |
| 5923 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5924 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5925 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5926 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5927 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5928 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5929 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5930 | break; |
| 5931 | } |
| 5932 | return desired_class_load_kind; |
| 5933 | } |
| 5934 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5935 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5936 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5937 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5938 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5939 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5940 | cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5941 | Location::RegisterLocation(RAX), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5942 | Location::RegisterLocation(RAX)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5943 | return; |
| 5944 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5945 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5946 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5947 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5948 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5949 | ? LocationSummary::kCallOnSlowPath |
| 5950 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5951 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5952 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5953 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5954 | } |
| 5955 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5956 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5957 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5958 | } |
| 5959 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5960 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5961 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5962 | // Rely on the type resolution and/or initialization to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5963 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5964 | } else { |
| 5965 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5966 | } |
| 5967 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5968 | } |
| 5969 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5970 | Label* CodeGeneratorX86_64::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5971 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5972 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5973 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5974 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5975 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5976 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 5977 | return &info->label; |
| 5978 | } |
| 5979 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5980 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5981 | // move. |
| 5982 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5983 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5984 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5985 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5986 | return; |
| 5987 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5988 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5989 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5990 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5991 | Location out_loc = locations->Out(); |
| 5992 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5993 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5994 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5995 | ? kWithoutReadBarrier |
| 5996 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5997 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5998 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5999 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6000 | DCHECK(!cls->CanCallRuntime()); |
| 6001 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6002 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6003 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6004 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6005 | cls, |
| 6006 | out_loc, |
| 6007 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6008 | /* fixup_label= */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6009 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6010 | break; |
| 6011 | } |
| 6012 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6013 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6014 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6015 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6016 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6017 | codegen_->RecordBootImageTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6018 | break; |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6019 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6020 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6021 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6022 | codegen_->RecordBootImageRelRoPatch(codegen_->GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6023 | break; |
| 6024 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6025 | case HLoadClass::LoadKind::kBssEntry: { |
| 6026 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6027 | /* no_rip= */ false); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6028 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6029 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 6030 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6031 | // No need for memory fence, thanks to the x86-64 memory model. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6032 | generate_null_check = true; |
| 6033 | break; |
| 6034 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6035 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 6036 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6037 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 6038 | DCHECK_NE(address, 0u); |
| 6039 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| 6040 | break; |
| 6041 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6042 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6043 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6044 | /* no_rip= */ true); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6045 | Label* fixup_label = |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6046 | codegen_->NewJitRootClassPatch(cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6047 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6048 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6049 | break; |
| 6050 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6051 | default: |
| 6052 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 6053 | UNREACHABLE(); |
| 6054 | } |
| 6055 | |
| 6056 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6057 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6058 | SlowPathCode* slow_path = |
| 6059 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6060 | codegen_->AddSlowPath(slow_path); |
| 6061 | if (generate_null_check) { |
| 6062 | __ testl(out, out); |
| 6063 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6064 | } |
| 6065 | if (cls->MustGenerateClinitCheck()) { |
| 6066 | GenerateClassInitializationCheck(slow_path, out); |
| 6067 | } else { |
| 6068 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6069 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6070 | } |
| 6071 | } |
| 6072 | |
| 6073 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 6074 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6075 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6076 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6077 | if (check->HasUses()) { |
| 6078 | locations->SetOut(Location::SameAsFirstInput()); |
| 6079 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6080 | // Rely on the type initialization to save everything we need. |
| 6081 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6082 | } |
| 6083 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6084 | void LocationsBuilderX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6085 | // Custom calling convention: RAX serves as both input and output. |
| 6086 | Location location = Location::RegisterLocation(RAX); |
| 6087 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 6088 | } |
| 6089 | |
| 6090 | void InstructionCodeGeneratorX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6091 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 6092 | } |
| 6093 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6094 | void LocationsBuilderX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 6095 | // Custom calling convention: RAX serves as both input and output. |
| 6096 | Location location = Location::RegisterLocation(RAX); |
| 6097 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 6098 | } |
| 6099 | |
| 6100 | void InstructionCodeGeneratorX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 6101 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 6102 | } |
| 6103 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6104 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6105 | // We assume the class to not be null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6106 | SlowPathCode* slow_path = |
| 6107 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64(check->GetLoadClass(), check); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6108 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6109 | GenerateClassInitializationCheck(slow_path, |
| 6110 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6111 | } |
| 6112 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6113 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 6114 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6115 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6116 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6117 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6118 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6119 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6120 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6121 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6122 | case HLoadString::LoadKind::kJitTableAddress: |
| 6123 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6124 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6125 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6126 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6127 | } |
| 6128 | return desired_string_load_kind; |
| 6129 | } |
| 6130 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6131 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6132 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6133 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6134 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6135 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 6136 | } else { |
| 6137 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6138 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 6139 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6140 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6141 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6142 | } else { |
| 6143 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6144 | } |
| 6145 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6146 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6147 | } |
| 6148 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6149 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6150 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6151 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6152 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6153 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6154 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6155 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6156 | return &info->label; |
| 6157 | } |
| 6158 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6159 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6160 | // move. |
| 6161 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6162 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6163 | Location out_loc = locations->Out(); |
| 6164 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6165 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6166 | switch (load->GetLoadKind()) { |
| 6167 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6168 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6169 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6170 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6171 | codegen_->RecordBootImageStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6172 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6173 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6174 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6175 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6176 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6177 | codegen_->RecordBootImageRelRoPatch(codegen_->GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6178 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6179 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6180 | case HLoadString::LoadKind::kBssEntry: { |
| 6181 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6182 | /* no_rip= */ false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6183 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 6184 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6185 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6186 | // No need for memory fence, thanks to the x86-64 memory model. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6187 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86_64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6188 | codegen_->AddSlowPath(slow_path); |
| 6189 | __ testl(out, out); |
| 6190 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6191 | __ Bind(slow_path->GetExitLabel()); |
| 6192 | return; |
| 6193 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6194 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 6195 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 6196 | DCHECK_NE(address, 0u); |
| 6197 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| 6198 | return; |
| 6199 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6200 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6201 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6202 | /* no_rip= */ true); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6203 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 6204 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6205 | // /* GcRoot<mirror::String> */ out = *address |
| 6206 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6207 | return; |
| 6208 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6209 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6210 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6211 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6212 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6213 | // 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] | 6214 | // Custom calling convention: RAX serves as both input and output. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6215 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6216 | codegen_->InvokeRuntime(kQuickResolveString, |
| 6217 | load, |
| 6218 | load->GetDexPc()); |
| 6219 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6220 | } |
| 6221 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6222 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6223 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6224 | /* no_rip= */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6225 | } |
| 6226 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6227 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 6228 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6229 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6230 | locations->SetOut(Location::RequiresRegister()); |
| 6231 | } |
| 6232 | |
| 6233 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6234 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 6235 | } |
| 6236 | |
| 6237 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6238 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6239 | } |
| 6240 | |
| 6241 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6242 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6243 | } |
| 6244 | |
| 6245 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6246 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6247 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6248 | InvokeRuntimeCallingConvention calling_convention; |
| 6249 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6250 | } |
| 6251 | |
| 6252 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6253 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6254 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6255 | } |
| 6256 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6257 | // Temp is used for read barrier. |
| 6258 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6259 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6260 | !kUseBakerReadBarrier && |
| 6261 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6262 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6263 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6264 | return 1; |
| 6265 | } |
| 6266 | return 0; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6267 | } |
| 6268 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6269 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 6270 | // interface pointer, the current interface is compared in memory. |
| 6271 | // The other checks have one temp for loading the object's class. |
| 6272 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6273 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6274 | return 2; |
| 6275 | } |
| 6276 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6277 | } |
| 6278 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6279 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6280 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6281 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6282 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6283 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6284 | case TypeCheckKind::kExactCheck: |
| 6285 | case TypeCheckKind::kAbstractClassCheck: |
| 6286 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6287 | case TypeCheckKind::kArrayObjectCheck: { |
| 6288 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6289 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6290 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6291 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6292 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6293 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6294 | case TypeCheckKind::kUnresolvedCheck: |
| 6295 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6296 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6297 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6298 | case TypeCheckKind::kBitstringCheck: |
| 6299 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6300 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6301 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6302 | LocationSummary* locations = |
| 6303 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6304 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6305 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6306 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6307 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6308 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6309 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6310 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6311 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 6312 | } else { |
| 6313 | locations->SetInAt(1, Location::Any()); |
| 6314 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6315 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 6316 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6317 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6318 | } |
| 6319 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6320 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6321 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6322 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6323 | Location obj_loc = locations->InAt(0); |
| 6324 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6325 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6326 | Location out_loc = locations->Out(); |
| 6327 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6328 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6329 | DCHECK_LE(num_temps, 1u); |
| 6330 | Location maybe_temp_loc = (num_temps >= 1u) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6331 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6332 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6333 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6334 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6335 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6336 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6337 | |
| 6338 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6339 | // Avoid null check if we know obj is not null. |
| 6340 | if (instruction->MustDoNullCheck()) { |
| 6341 | __ testl(obj, obj); |
| 6342 | __ j(kEqual, &zero); |
| 6343 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6344 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6345 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6346 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6347 | ReadBarrierOption read_barrier_option = |
| 6348 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6349 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6350 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6351 | out_loc, |
| 6352 | obj_loc, |
| 6353 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6354 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6355 | if (cls.IsRegister()) { |
| 6356 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6357 | } else { |
| 6358 | DCHECK(cls.IsStackSlot()) << cls; |
| 6359 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6360 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6361 | if (zero.IsLinked()) { |
| 6362 | // Classes must be equal for the instanceof to succeed. |
| 6363 | __ j(kNotEqual, &zero); |
| 6364 | __ movl(out, Immediate(1)); |
| 6365 | __ jmp(&done); |
| 6366 | } else { |
| 6367 | __ setcc(kEqual, out); |
| 6368 | // setcc only sets the low byte. |
| 6369 | __ andl(out, Immediate(1)); |
| 6370 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6371 | break; |
| 6372 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6373 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6374 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6375 | ReadBarrierOption read_barrier_option = |
| 6376 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6377 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6378 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6379 | out_loc, |
| 6380 | obj_loc, |
| 6381 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6382 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6383 | // If the class is abstract, we eagerly fetch the super class of the |
| 6384 | // object to avoid doing a comparison we know will fail. |
| 6385 | NearLabel loop, success; |
| 6386 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6387 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6388 | GenerateReferenceLoadOneRegister(instruction, |
| 6389 | out_loc, |
| 6390 | super_offset, |
| 6391 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6392 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6393 | __ testl(out, out); |
| 6394 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6395 | __ j(kEqual, &done); |
| 6396 | if (cls.IsRegister()) { |
| 6397 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6398 | } else { |
| 6399 | DCHECK(cls.IsStackSlot()) << cls; |
| 6400 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6401 | } |
| 6402 | __ j(kNotEqual, &loop); |
| 6403 | __ movl(out, Immediate(1)); |
| 6404 | if (zero.IsLinked()) { |
| 6405 | __ jmp(&done); |
| 6406 | } |
| 6407 | break; |
| 6408 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6409 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6410 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6411 | ReadBarrierOption read_barrier_option = |
| 6412 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6413 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6414 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6415 | out_loc, |
| 6416 | obj_loc, |
| 6417 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6418 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6419 | // Walk over the class hierarchy to find a match. |
| 6420 | NearLabel loop, success; |
| 6421 | __ Bind(&loop); |
| 6422 | if (cls.IsRegister()) { |
| 6423 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6424 | } else { |
| 6425 | DCHECK(cls.IsStackSlot()) << cls; |
| 6426 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6427 | } |
| 6428 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6429 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6430 | GenerateReferenceLoadOneRegister(instruction, |
| 6431 | out_loc, |
| 6432 | super_offset, |
| 6433 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6434 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6435 | __ testl(out, out); |
| 6436 | __ j(kNotEqual, &loop); |
| 6437 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6438 | __ jmp(&done); |
| 6439 | __ Bind(&success); |
| 6440 | __ movl(out, Immediate(1)); |
| 6441 | if (zero.IsLinked()) { |
| 6442 | __ jmp(&done); |
| 6443 | } |
| 6444 | break; |
| 6445 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6446 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6447 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6448 | ReadBarrierOption read_barrier_option = |
| 6449 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6450 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6451 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6452 | out_loc, |
| 6453 | obj_loc, |
| 6454 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6455 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6456 | // Do an exact check. |
| 6457 | NearLabel exact_check; |
| 6458 | if (cls.IsRegister()) { |
| 6459 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6460 | } else { |
| 6461 | DCHECK(cls.IsStackSlot()) << cls; |
| 6462 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6463 | } |
| 6464 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6465 | // 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] | 6466 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6467 | GenerateReferenceLoadOneRegister(instruction, |
| 6468 | out_loc, |
| 6469 | component_offset, |
| 6470 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6471 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6472 | __ testl(out, out); |
| 6473 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6474 | __ j(kEqual, &done); |
| 6475 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6476 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6477 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6478 | __ movl(out, Immediate(1)); |
| 6479 | __ jmp(&done); |
| 6480 | break; |
| 6481 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6482 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6483 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6484 | // No read barrier since the slow path will retry upon failure. |
| 6485 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6486 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6487 | out_loc, |
| 6488 | obj_loc, |
| 6489 | class_offset, |
| 6490 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6491 | if (cls.IsRegister()) { |
| 6492 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6493 | } else { |
| 6494 | DCHECK(cls.IsStackSlot()) << cls; |
| 6495 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6496 | } |
| 6497 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6498 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6499 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6500 | codegen_->AddSlowPath(slow_path); |
| 6501 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6502 | __ movl(out, Immediate(1)); |
| 6503 | if (zero.IsLinked()) { |
| 6504 | __ jmp(&done); |
| 6505 | } |
| 6506 | break; |
| 6507 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6508 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6509 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6510 | case TypeCheckKind::kInterfaceCheck: { |
| 6511 | // 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] | 6512 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6513 | // cases. |
| 6514 | // |
| 6515 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6516 | // entry point without resorting to a type checking slow path |
| 6517 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6518 | // require to assign fixed registers for the inputs of this |
| 6519 | // HInstanceOf instruction (following the runtime calling |
| 6520 | // convention), which might be cluttered by the potential first |
| 6521 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6522 | // |
| 6523 | // TODO: Introduce a new runtime entry point taking the object |
| 6524 | // to test (instead of its class) as argument, and let it deal |
| 6525 | // with the read barrier issues. This will let us refactor this |
| 6526 | // case of the `switch` code as it was previously (with a direct |
| 6527 | // call to the runtime not using a type checking slow path). |
| 6528 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6529 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6530 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6531 | instruction, /* is_fatal= */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6532 | codegen_->AddSlowPath(slow_path); |
| 6533 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6534 | if (zero.IsLinked()) { |
| 6535 | __ jmp(&done); |
| 6536 | } |
| 6537 | break; |
| 6538 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6539 | |
| 6540 | case TypeCheckKind::kBitstringCheck: { |
| 6541 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6542 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6543 | out_loc, |
| 6544 | obj_loc, |
| 6545 | class_offset, |
| 6546 | kWithoutReadBarrier); |
| 6547 | |
| 6548 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 6549 | if (zero.IsLinked()) { |
| 6550 | __ j(kNotEqual, &zero); |
| 6551 | __ movl(out, Immediate(1)); |
| 6552 | __ jmp(&done); |
| 6553 | } else { |
| 6554 | __ setcc(kEqual, out); |
| 6555 | // setcc only sets the low byte. |
| 6556 | __ andl(out, Immediate(1)); |
| 6557 | } |
| 6558 | break; |
| 6559 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6560 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6561 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6562 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6563 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6564 | __ xorl(out, out); |
| 6565 | } |
| 6566 | |
| 6567 | if (done.IsLinked()) { |
| 6568 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6569 | } |
| 6570 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6571 | if (slow_path != nullptr) { |
| 6572 | __ Bind(slow_path->GetExitLabel()); |
| 6573 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6574 | } |
| 6575 | |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6576 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6577 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6578 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6579 | LocationSummary* locations = |
| 6580 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6581 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6582 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6583 | // Require a register for the interface check since there is a loop that compares the class to |
| 6584 | // a memory address. |
| 6585 | locations->SetInAt(1, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6586 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6587 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6588 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6589 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6590 | } else { |
| 6591 | locations->SetInAt(1, Location::Any()); |
| 6592 | } |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6593 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathX86. |
| 6594 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6595 | } |
| 6596 | |
| 6597 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6598 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6599 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6600 | Location obj_loc = locations->InAt(0); |
| 6601 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6602 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6603 | Location temp_loc = locations->GetTemp(0); |
| 6604 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6605 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6606 | DCHECK_GE(num_temps, 1u); |
| 6607 | DCHECK_LE(num_temps, 2u); |
| 6608 | Location maybe_temp2_loc = (num_temps >= 2u) ? locations->GetTemp(1) : Location::NoLocation(); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6609 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6610 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6611 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6612 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6613 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6614 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6615 | const uint32_t object_array_data_offset = |
| 6616 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6617 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6618 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6619 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6620 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6621 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6622 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6623 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6624 | |
| 6625 | NearLabel done; |
| 6626 | // Avoid null check if we know obj is not null. |
| 6627 | if (instruction->MustDoNullCheck()) { |
| 6628 | __ testl(obj, obj); |
| 6629 | __ j(kEqual, &done); |
| 6630 | } |
| 6631 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6632 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6633 | case TypeCheckKind::kExactCheck: |
| 6634 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6635 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6636 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6637 | temp_loc, |
| 6638 | obj_loc, |
| 6639 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6640 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6641 | if (cls.IsRegister()) { |
| 6642 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6643 | } else { |
| 6644 | DCHECK(cls.IsStackSlot()) << cls; |
| 6645 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6646 | } |
| 6647 | // Jump to slow path for throwing the exception or doing a |
| 6648 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6649 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6650 | break; |
| 6651 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6652 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6653 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6654 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6655 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6656 | temp_loc, |
| 6657 | obj_loc, |
| 6658 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6659 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6660 | // If the class is abstract, we eagerly fetch the super class of the |
| 6661 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6662 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6663 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6664 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6665 | GenerateReferenceLoadOneRegister(instruction, |
| 6666 | temp_loc, |
| 6667 | super_offset, |
| 6668 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6669 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6670 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6671 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6672 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6673 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6674 | // Otherwise, compare the classes. |
| 6675 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6676 | if (cls.IsRegister()) { |
| 6677 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6678 | } else { |
| 6679 | DCHECK(cls.IsStackSlot()) << cls; |
| 6680 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6681 | } |
| 6682 | __ j(kNotEqual, &loop); |
| 6683 | break; |
| 6684 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6685 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6686 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6687 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6688 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6689 | temp_loc, |
| 6690 | obj_loc, |
| 6691 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6692 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6693 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6694 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6695 | __ Bind(&loop); |
| 6696 | if (cls.IsRegister()) { |
| 6697 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6698 | } else { |
| 6699 | DCHECK(cls.IsStackSlot()) << cls; |
| 6700 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6701 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6702 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6703 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6704 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6705 | GenerateReferenceLoadOneRegister(instruction, |
| 6706 | temp_loc, |
| 6707 | super_offset, |
| 6708 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6709 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6710 | |
| 6711 | // If the class reference currently in `temp` is not null, jump |
| 6712 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6713 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6714 | __ j(kNotZero, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6715 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6716 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6717 | break; |
| 6718 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6719 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6720 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6721 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6722 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6723 | temp_loc, |
| 6724 | obj_loc, |
| 6725 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6726 | kWithoutReadBarrier); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6727 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6728 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6729 | if (cls.IsRegister()) { |
| 6730 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6731 | } else { |
| 6732 | DCHECK(cls.IsStackSlot()) << cls; |
| 6733 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6734 | } |
| 6735 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6736 | |
| 6737 | // 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] | 6738 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6739 | GenerateReferenceLoadOneRegister(instruction, |
| 6740 | temp_loc, |
| 6741 | component_offset, |
| 6742 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6743 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6744 | |
| 6745 | // If the component type is not null (i.e. the object is indeed |
| 6746 | // an array), jump to label `check_non_primitive_component_type` |
| 6747 | // to further check that this component type is not a primitive |
| 6748 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6749 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6750 | // Otherwise, jump to the slow path to throw the exception. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6751 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6752 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6753 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6754 | break; |
| 6755 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6756 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6757 | case TypeCheckKind::kUnresolvedCheck: { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6758 | // 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] | 6759 | // |
| 6760 | // We cannot directly call the CheckCast runtime entry point |
| 6761 | // without resorting to a type checking slow path here (i.e. by |
| 6762 | // calling InvokeRuntime directly), as it would require to |
| 6763 | // assign fixed registers for the inputs of this HInstanceOf |
| 6764 | // instruction (following the runtime calling convention), which |
| 6765 | // might be cluttered by the potential first read barrier |
| 6766 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6767 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6768 | break; |
| 6769 | } |
| 6770 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6771 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6772 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 6773 | // We can not get false positives by doing this. |
| 6774 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6775 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6776 | temp_loc, |
| 6777 | obj_loc, |
| 6778 | class_offset, |
| 6779 | kWithoutReadBarrier); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6780 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6781 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6782 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6783 | temp_loc, |
| 6784 | temp_loc, |
| 6785 | iftable_offset, |
| 6786 | kWithoutReadBarrier); |
| 6787 | // Iftable is never null. |
| 6788 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
| 6789 | // Maybe poison the `cls` for direct comparison with memory. |
| 6790 | __ MaybePoisonHeapReference(cls.AsRegister<CpuRegister>()); |
| 6791 | // Loop through the iftable and check if any class matches. |
| 6792 | NearLabel start_loop; |
| 6793 | __ Bind(&start_loop); |
| 6794 | // Need to subtract first to handle the empty array case. |
| 6795 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| 6796 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6797 | // Go to next interface if the classes do not match. |
| 6798 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 6799 | CodeGeneratorX86_64::ArrayAddress(temp, |
| 6800 | maybe_temp2_loc, |
| 6801 | TIMES_4, |
| 6802 | object_array_data_offset)); |
| 6803 | __ j(kNotEqual, &start_loop); // Return if same class. |
| 6804 | // If `cls` was poisoned above, unpoison it. |
| 6805 | __ MaybeUnpoisonHeapReference(cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6806 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6807 | } |
| 6808 | |
| 6809 | case TypeCheckKind::kBitstringCheck: { |
| 6810 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6811 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6812 | temp_loc, |
| 6813 | obj_loc, |
| 6814 | class_offset, |
| 6815 | kWithoutReadBarrier); |
| 6816 | |
| 6817 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 6818 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 6819 | break; |
| 6820 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6821 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6822 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6823 | if (done.IsLinked()) { |
| 6824 | __ Bind(&done); |
| 6825 | } |
| 6826 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6827 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6828 | } |
| 6829 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6830 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6831 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6832 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6833 | InvokeRuntimeCallingConvention calling_convention; |
| 6834 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6835 | } |
| 6836 | |
| 6837 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6838 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6839 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6840 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6841 | if (instruction->IsEnter()) { |
| 6842 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6843 | } else { |
| 6844 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6845 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6846 | } |
| 6847 | |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 6848 | void LocationsBuilderX86_64::VisitX86AndNot(HX86AndNot* instruction) { |
| 6849 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 6850 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 6851 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 6852 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6853 | // There is no immediate variant of negated bitwise and in X86. |
| 6854 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6855 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6856 | } |
| 6857 | |
| 6858 | void LocationsBuilderX86_64::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 6859 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 6860 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 6861 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 6862 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6863 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6864 | } |
| 6865 | |
| 6866 | void InstructionCodeGeneratorX86_64::VisitX86AndNot(HX86AndNot* instruction) { |
| 6867 | LocationSummary* locations = instruction->GetLocations(); |
| 6868 | Location first = locations->InAt(0); |
| 6869 | Location second = locations->InAt(1); |
| 6870 | Location dest = locations->Out(); |
| 6871 | __ andn(dest.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 6872 | } |
| 6873 | |
| 6874 | void InstructionCodeGeneratorX86_64::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 6875 | LocationSummary* locations = instruction->GetLocations(); |
| 6876 | Location src = locations->InAt(0); |
| 6877 | Location dest = locations->Out(); |
| 6878 | switch (instruction->GetOpKind()) { |
| 6879 | case HInstruction::kAnd: |
| 6880 | __ blsr(dest.AsRegister<CpuRegister>(), src.AsRegister<CpuRegister>()); |
| 6881 | break; |
| 6882 | case HInstruction::kXor: |
| 6883 | __ blsmsk(dest.AsRegister<CpuRegister>(), src.AsRegister<CpuRegister>()); |
| 6884 | break; |
| 6885 | default: |
| 6886 | LOG(FATAL) << "Unreachable"; |
| 6887 | } |
| 6888 | } |
| 6889 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6890 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6891 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6892 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6893 | |
| 6894 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6895 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6896 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6897 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 6898 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6899 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6900 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6901 | locations->SetOut(Location::SameAsFirstInput()); |
| 6902 | } |
| 6903 | |
| 6904 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6905 | HandleBitwiseOperation(instruction); |
| 6906 | } |
| 6907 | |
| 6908 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6909 | HandleBitwiseOperation(instruction); |
| 6910 | } |
| 6911 | |
| 6912 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6913 | HandleBitwiseOperation(instruction); |
| 6914 | } |
| 6915 | |
| 6916 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6917 | LocationSummary* locations = instruction->GetLocations(); |
| 6918 | Location first = locations->InAt(0); |
| 6919 | Location second = locations->InAt(1); |
| 6920 | DCHECK(first.Equals(locations->Out())); |
| 6921 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6922 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6923 | if (second.IsRegister()) { |
| 6924 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6925 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6926 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6927 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6928 | } else { |
| 6929 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6930 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6931 | } |
| 6932 | } else if (second.IsConstant()) { |
| 6933 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6934 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6935 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6936 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6937 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6938 | } else { |
| 6939 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6940 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6941 | } |
| 6942 | } else { |
| 6943 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6944 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6945 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6946 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6947 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6948 | } else { |
| 6949 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6950 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6951 | } |
| 6952 | } |
| 6953 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6954 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6955 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6956 | bool second_is_constant = false; |
| 6957 | int64_t value = 0; |
| 6958 | if (second.IsConstant()) { |
| 6959 | second_is_constant = true; |
| 6960 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6961 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6962 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6963 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6964 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6965 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6966 | if (is_int32_value) { |
| 6967 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6968 | } else { |
| 6969 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6970 | } |
| 6971 | } else if (second.IsDoubleStackSlot()) { |
| 6972 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6973 | } else { |
| 6974 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6975 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6976 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6977 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6978 | if (is_int32_value) { |
| 6979 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6980 | } else { |
| 6981 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6982 | } |
| 6983 | } else if (second.IsDoubleStackSlot()) { |
| 6984 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6985 | } else { |
| 6986 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6987 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6988 | } else { |
| 6989 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6990 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6991 | if (is_int32_value) { |
| 6992 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6993 | } else { |
| 6994 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6995 | } |
| 6996 | } else if (second.IsDoubleStackSlot()) { |
| 6997 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6998 | } else { |
| 6999 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 7000 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7001 | } |
| 7002 | } |
| 7003 | } |
| 7004 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7005 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister( |
| 7006 | HInstruction* instruction, |
| 7007 | Location out, |
| 7008 | uint32_t offset, |
| 7009 | Location maybe_temp, |
| 7010 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7011 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7012 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7013 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7014 | if (kUseBakerReadBarrier) { |
| 7015 | // Load with fast path based Baker's read barrier. |
| 7016 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7017 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7018 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7019 | } else { |
| 7020 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7021 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7022 | // in the following move operation, as we will need it for the |
| 7023 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7024 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7025 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7026 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7027 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7028 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7029 | } |
| 7030 | } else { |
| 7031 | // Plain load with no read barrier. |
| 7032 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7033 | __ movl(out_reg, Address(out_reg, offset)); |
| 7034 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7035 | } |
| 7036 | } |
| 7037 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7038 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters( |
| 7039 | HInstruction* instruction, |
| 7040 | Location out, |
| 7041 | Location obj, |
| 7042 | uint32_t offset, |
| 7043 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7044 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 7045 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7046 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7047 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7048 | if (kUseBakerReadBarrier) { |
| 7049 | // Load with fast path based Baker's read barrier. |
| 7050 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7051 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7052 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7053 | } else { |
| 7054 | // Load with slow path based read barrier. |
| 7055 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7056 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7057 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7058 | } |
| 7059 | } else { |
| 7060 | // Plain load with no read barrier. |
| 7061 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7062 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7063 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7064 | } |
| 7065 | } |
| 7066 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7067 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad( |
| 7068 | HInstruction* instruction, |
| 7069 | Location root, |
| 7070 | const Address& address, |
| 7071 | Label* fixup_label, |
| 7072 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7073 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7074 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7075 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7076 | if (kUseBakerReadBarrier) { |
| 7077 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7078 | // Baker's read barrier are used: |
| 7079 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7080 | // root = obj.field; |
| 7081 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7082 | // if (temp != null) { |
| 7083 | // root = temp(root) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7084 | // } |
| 7085 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7086 | // /* GcRoot<mirror::Object> */ root = *address |
| 7087 | __ movl(root_reg, address); |
| 7088 | if (fixup_label != nullptr) { |
| 7089 | __ Bind(fixup_label); |
| 7090 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7091 | static_assert( |
| 7092 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7093 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7094 | "have different sizes."); |
| 7095 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7096 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7097 | "have different sizes."); |
| 7098 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7099 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7100 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7101 | instruction, root, /* unpoison_ref_before_marking= */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7102 | codegen_->AddSlowPath(slow_path); |
| 7103 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7104 | // Test the `Thread::Current()->pReadBarrierMarkReg ## root.reg()` entrypoint. |
| 7105 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7106 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(root.reg()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7107 | __ gs()->cmpl(Address::Absolute(entry_point_offset, /* no_rip= */ true), Immediate(0)); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7108 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7109 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7110 | __ Bind(slow_path->GetExitLabel()); |
| 7111 | } else { |
| 7112 | // GC root loaded through a slow path for read barriers other |
| 7113 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7114 | // /* GcRoot<mirror::Object>* */ root = address |
| 7115 | __ leaq(root_reg, address); |
| 7116 | if (fixup_label != nullptr) { |
| 7117 | __ Bind(fixup_label); |
| 7118 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7119 | // /* mirror::Object* */ root = root->Read() |
| 7120 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7121 | } |
| 7122 | } else { |
| 7123 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7124 | // /* GcRoot<mirror::Object> */ root = *address |
| 7125 | __ movl(root_reg, address); |
| 7126 | if (fixup_label != nullptr) { |
| 7127 | __ Bind(fixup_label); |
| 7128 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7129 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7130 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7131 | } |
| 7132 | } |
| 7133 | |
| 7134 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7135 | Location ref, |
| 7136 | CpuRegister obj, |
| 7137 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7138 | bool needs_null_check) { |
| 7139 | DCHECK(kEmitCompilerReadBarrier); |
| 7140 | DCHECK(kUseBakerReadBarrier); |
| 7141 | |
| 7142 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7143 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7144 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7145 | } |
| 7146 | |
| 7147 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7148 | Location ref, |
| 7149 | CpuRegister obj, |
| 7150 | uint32_t data_offset, |
| 7151 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7152 | bool needs_null_check) { |
| 7153 | DCHECK(kEmitCompilerReadBarrier); |
| 7154 | DCHECK(kUseBakerReadBarrier); |
| 7155 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7156 | static_assert( |
| 7157 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7158 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7159 | // /* HeapReference<Object> */ ref = |
| 7160 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7161 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7162 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7163 | } |
| 7164 | |
| 7165 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7166 | Location ref, |
| 7167 | CpuRegister obj, |
| 7168 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7169 | bool needs_null_check, |
| 7170 | bool always_update_field, |
| 7171 | CpuRegister* temp1, |
| 7172 | CpuRegister* temp2) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7173 | DCHECK(kEmitCompilerReadBarrier); |
| 7174 | DCHECK(kUseBakerReadBarrier); |
| 7175 | |
| 7176 | // In slow path based read barriers, the read barrier call is |
| 7177 | // inserted after the original load. However, in fast path based |
| 7178 | // Baker's read barriers, we need to perform the load of |
| 7179 | // mirror::Object::monitor_ *before* the original reference load. |
| 7180 | // This load-load ordering is required by the read barrier. |
| 7181 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7182 | // |
| 7183 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7184 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7185 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7186 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7187 | // if (is_gray) { |
| 7188 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7189 | // } |
| 7190 | // |
| 7191 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7192 | // slightly more complex as: |
| 7193 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7194 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7195 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 7196 | // 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] | 7197 | // - it performs additional checks that we do not do here for |
| 7198 | // performance reasons. |
| 7199 | |
| 7200 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7201 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7202 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7203 | // 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] | 7204 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7205 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7206 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7207 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7208 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7209 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7210 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7211 | // ref = ReadBarrier::Mark(ref); |
| 7212 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7213 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7214 | if (needs_null_check) { |
| 7215 | MaybeRecordImplicitNullCheck(instruction); |
| 7216 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7217 | |
| 7218 | // Load fence to prevent load-load reordering. |
| 7219 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 7220 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7221 | |
| 7222 | // The actual reference load. |
| 7223 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7224 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7225 | |
| 7226 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7227 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7228 | SlowPathCode* slow_path; |
| 7229 | if (always_update_field) { |
| 7230 | DCHECK(temp1 != nullptr); |
| 7231 | DCHECK(temp2 != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7232 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7233 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp1, *temp2); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7234 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7235 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7236 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7237 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7238 | AddSlowPath(slow_path); |
| 7239 | |
| 7240 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7241 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7242 | |
| 7243 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7244 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7245 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7246 | __ Bind(slow_path->GetExitLabel()); |
| 7247 | } |
| 7248 | |
| 7249 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7250 | Location out, |
| 7251 | Location ref, |
| 7252 | Location obj, |
| 7253 | uint32_t offset, |
| 7254 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7255 | DCHECK(kEmitCompilerReadBarrier); |
| 7256 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7257 | // Insert a slow path based read barrier *after* the reference load. |
| 7258 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7259 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7260 | // reference will be carried out by the runtime within the slow |
| 7261 | // path. |
| 7262 | // |
| 7263 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7264 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7265 | // not used by the artReadBarrierSlow entry point. |
| 7266 | // |
| 7267 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7268 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7269 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 7270 | AddSlowPath(slow_path); |
| 7271 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7272 | __ jmp(slow_path->GetEntryLabel()); |
| 7273 | __ Bind(slow_path->GetExitLabel()); |
| 7274 | } |
| 7275 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7276 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7277 | Location out, |
| 7278 | Location ref, |
| 7279 | Location obj, |
| 7280 | uint32_t offset, |
| 7281 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7282 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7283 | // Baker's read barriers shall be handled by the fast path |
| 7284 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 7285 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7286 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7287 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7288 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7289 | } else if (kPoisonHeapReferences) { |
| 7290 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 7291 | } |
| 7292 | } |
| 7293 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7294 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7295 | Location out, |
| 7296 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7297 | DCHECK(kEmitCompilerReadBarrier); |
| 7298 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7299 | // Insert a slow path based read barrier *after* the GC root load. |
| 7300 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7301 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7302 | // not need to do anything special for this here. |
| 7303 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7304 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7305 | AddSlowPath(slow_path); |
| 7306 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7307 | __ jmp(slow_path->GetEntryLabel()); |
| 7308 | __ Bind(slow_path->GetExitLabel()); |
| 7309 | } |
| 7310 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7311 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7312 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7313 | LOG(FATAL) << "Unreachable"; |
| 7314 | } |
| 7315 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7316 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7317 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7318 | LOG(FATAL) << "Unreachable"; |
| 7319 | } |
| 7320 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7321 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7322 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7323 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7324 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7325 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7326 | locations->AddTemp(Location::RequiresRegister()); |
| 7327 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7328 | } |
| 7329 | |
| 7330 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7331 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7332 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7333 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7334 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 7335 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 7336 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7337 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7338 | |
| 7339 | // Should we generate smaller inline compare/jumps? |
| 7340 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7341 | // Figure out the correct compare values and jump conditions. |
| 7342 | // Handle the first compare/branch as a special case because it might |
| 7343 | // jump to the default case. |
| 7344 | DCHECK_GT(num_entries, 2u); |
| 7345 | Condition first_condition; |
| 7346 | uint32_t index; |
| 7347 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7348 | if (lower_bound != 0) { |
| 7349 | first_condition = kLess; |
| 7350 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 7351 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7352 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 7353 | |
| 7354 | index = 1; |
| 7355 | } else { |
| 7356 | // Handle all the compare/jumps below. |
| 7357 | first_condition = kBelow; |
| 7358 | index = 0; |
| 7359 | } |
| 7360 | |
| 7361 | // Handle the rest of the compare/jumps. |
| 7362 | for (; index + 1 < num_entries; index += 2) { |
| 7363 | int32_t compare_to_value = lower_bound + index + 1; |
| 7364 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 7365 | // Jump to successors[index] if value < case_value[index]. |
| 7366 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7367 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7368 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7369 | } |
| 7370 | |
| 7371 | if (index != num_entries) { |
| 7372 | // There are an odd number of entries. Handle the last one. |
| 7373 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 7374 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7375 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 7376 | } |
| 7377 | |
| 7378 | // And the default for any other value. |
| 7379 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7380 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 7381 | } |
| 7382 | return; |
| 7383 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7384 | |
| 7385 | // Remove the bias, if needed. |
| 7386 | Register value_reg_out = value_reg_in.AsRegister(); |
| 7387 | if (lower_bound != 0) { |
| 7388 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 7389 | value_reg_out = temp_reg.AsRegister(); |
| 7390 | } |
| 7391 | CpuRegister value_reg(value_reg_out); |
| 7392 | |
| 7393 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7394 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7395 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7396 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7397 | // We are in the range of the table. |
| 7398 | // Load the address of the jump table in the constant area. |
| 7399 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7400 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7401 | // Load the (signed) offset from the jump table. |
| 7402 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 7403 | |
| 7404 | // Add the offset to the address of the table base. |
| 7405 | __ addq(temp_reg, base_reg); |
| 7406 | |
| 7407 | // And jump. |
| 7408 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7409 | } |
| 7410 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7411 | void LocationsBuilderX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7412 | ATTRIBUTE_UNUSED) { |
| 7413 | LOG(FATAL) << "Unreachable"; |
| 7414 | } |
| 7415 | |
| 7416 | void InstructionCodeGeneratorX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7417 | ATTRIBUTE_UNUSED) { |
| 7418 | LOG(FATAL) << "Unreachable"; |
| 7419 | } |
| 7420 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7421 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 7422 | if (value == 0) { |
| 7423 | __ xorl(dest, dest); |
| 7424 | } else { |
| 7425 | __ movl(dest, Immediate(value)); |
| 7426 | } |
| 7427 | } |
| 7428 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7429 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 7430 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7431 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7432 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 7433 | } else if (IsUint<32>(value)) { |
| 7434 | // 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] | 7435 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 7436 | } else { |
| 7437 | __ movq(dest, Immediate(value)); |
| 7438 | } |
| 7439 | } |
| 7440 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 7441 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 7442 | if (value == 0) { |
| 7443 | __ xorps(dest, dest); |
| 7444 | } else { |
| 7445 | __ movss(dest, LiteralInt32Address(value)); |
| 7446 | } |
| 7447 | } |
| 7448 | |
| 7449 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 7450 | if (value == 0) { |
| 7451 | __ xorpd(dest, dest); |
| 7452 | } else { |
| 7453 | __ movsd(dest, LiteralInt64Address(value)); |
| 7454 | } |
| 7455 | } |
| 7456 | |
| 7457 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 7458 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 7459 | } |
| 7460 | |
| 7461 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 7462 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 7463 | } |
| 7464 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7465 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 7466 | if (value == 0) { |
| 7467 | __ testl(dest, dest); |
| 7468 | } else { |
| 7469 | __ cmpl(dest, Immediate(value)); |
| 7470 | } |
| 7471 | } |
| 7472 | |
| 7473 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 7474 | if (IsInt<32>(value)) { |
| 7475 | if (value == 0) { |
| 7476 | __ testq(dest, dest); |
| 7477 | } else { |
| 7478 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 7479 | } |
| 7480 | } else { |
| 7481 | // Value won't fit in an int. |
| 7482 | __ cmpq(dest, LiteralInt64Address(value)); |
| 7483 | } |
| 7484 | } |
| 7485 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7486 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 7487 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7488 | GenerateIntCompare(lhs_reg, rhs); |
| 7489 | } |
| 7490 | |
| 7491 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7492 | if (rhs.IsConstant()) { |
| 7493 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7494 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7495 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7496 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7497 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7498 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7499 | } |
| 7500 | } |
| 7501 | |
| 7502 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 7503 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 7504 | if (rhs.IsConstant()) { |
| 7505 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 7506 | Compare64BitValue(lhs_reg, value); |
| 7507 | } else if (rhs.IsDoubleStackSlot()) { |
| 7508 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 7509 | } else { |
| 7510 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 7511 | } |
| 7512 | } |
| 7513 | |
| 7514 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 7515 | Location index, |
| 7516 | ScaleFactor scale, |
| 7517 | uint32_t data_offset) { |
| 7518 | return index.IsConstant() ? |
| 7519 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7520 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 7521 | } |
| 7522 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 7523 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 7524 | DCHECK(dest.IsDoubleStackSlot()); |
| 7525 | if (IsInt<32>(value)) { |
| 7526 | // Can move directly as an int32 constant. |
| 7527 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 7528 | Immediate(static_cast<int32_t>(value))); |
| 7529 | } else { |
| 7530 | Load64BitValue(CpuRegister(TMP), value); |
| 7531 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 7532 | } |
| 7533 | } |
| 7534 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7535 | /** |
| 7536 | * Class to handle late fixup of offsets into constant area. |
| 7537 | */ |
| 7538 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 7539 | public: |
| 7540 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 7541 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7542 | |
| 7543 | protected: |
| 7544 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7545 | |
| 7546 | CodeGeneratorX86_64* codegen_; |
| 7547 | |
| 7548 | private: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7549 | void Process(const MemoryRegion& region, int pos) override { |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7550 | // Patch the correct offset for the instruction. We use the address of the |
| 7551 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 7552 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7553 | int32_t relative_position = constant_offset - pos; |
| 7554 | |
| 7555 | // Patch in the right value. |
| 7556 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7557 | } |
| 7558 | |
| 7559 | // Location in constant area that the fixup refers to. |
| 7560 | size_t offset_into_constant_area_; |
| 7561 | }; |
| 7562 | |
| 7563 | /** |
| 7564 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7565 | * constant area. |
| 7566 | */ |
| 7567 | class JumpTableRIPFixup : public RIPFixup { |
| 7568 | public: |
| 7569 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 7570 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7571 | |
| 7572 | void CreateJumpTable() { |
| 7573 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7574 | |
| 7575 | // Ensure that the reference to the jump table has the correct offset. |
| 7576 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7577 | SetOffset(offset_in_constant_table); |
| 7578 | |
| 7579 | // Compute the offset from the start of the function to this jump table. |
| 7580 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7581 | |
| 7582 | // Populate the jump table with the correct values for the jump table. |
| 7583 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7584 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7585 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7586 | // The value that we want is the target offset - the position of the table. |
| 7587 | for (int32_t i = 0; i < num_entries; i++) { |
| 7588 | HBasicBlock* b = successors[i]; |
| 7589 | Label* l = codegen_->GetLabelOf(b); |
| 7590 | DCHECK(l->IsBound()); |
| 7591 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7592 | assembler->AppendInt32(offset_to_block); |
| 7593 | } |
| 7594 | } |
| 7595 | |
| 7596 | private: |
| 7597 | const HPackedSwitch* switch_instr_; |
| 7598 | }; |
| 7599 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7600 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7601 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7602 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7603 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7604 | // 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] | 7605 | assembler->Align(4, 0); |
| 7606 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7607 | |
| 7608 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7609 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7610 | jump_table->CreateJumpTable(); |
| 7611 | } |
| 7612 | |
| 7613 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7614 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7615 | } |
| 7616 | |
| 7617 | // And finish up. |
| 7618 | CodeGenerator::Finalize(allocator); |
| 7619 | } |
| 7620 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7621 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7622 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddDouble(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7623 | return Address::RIP(fixup); |
| 7624 | } |
| 7625 | |
| 7626 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7627 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddFloat(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7628 | return Address::RIP(fixup); |
| 7629 | } |
| 7630 | |
| 7631 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7632 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt32(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7633 | return Address::RIP(fixup); |
| 7634 | } |
| 7635 | |
| 7636 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7637 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt64(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7638 | return Address::RIP(fixup); |
| 7639 | } |
| 7640 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7641 | // TODO: trg as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7642 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7643 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7644 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7645 | return; |
| 7646 | } |
| 7647 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7648 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7649 | |
| 7650 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7651 | if (trg.Equals(return_loc)) { |
| 7652 | return; |
| 7653 | } |
| 7654 | |
| 7655 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7656 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7657 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7658 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7659 | } |
| 7660 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7661 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7662 | // Create a fixup to be used to create and address the jump table. |
| 7663 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7664 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7665 | |
| 7666 | // We have to populate the jump tables. |
| 7667 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7668 | return Address::RIP(table_fixup); |
| 7669 | } |
| 7670 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7671 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7672 | const Address& addr_high, |
| 7673 | int64_t v, |
| 7674 | HInstruction* instruction) { |
| 7675 | if (IsInt<32>(v)) { |
| 7676 | int32_t v_32 = v; |
| 7677 | __ movq(addr_low, Immediate(v_32)); |
| 7678 | MaybeRecordImplicitNullCheck(instruction); |
| 7679 | } else { |
| 7680 | // Didn't fit in a register. Do it in pieces. |
| 7681 | int32_t low_v = Low32Bits(v); |
| 7682 | int32_t high_v = High32Bits(v); |
| 7683 | __ movl(addr_low, Immediate(low_v)); |
| 7684 | MaybeRecordImplicitNullCheck(instruction); |
| 7685 | __ movl(addr_high, Immediate(high_v)); |
| 7686 | } |
| 7687 | } |
| 7688 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7689 | void CodeGeneratorX86_64::PatchJitRootUse(uint8_t* code, |
| 7690 | const uint8_t* roots_data, |
| 7691 | const PatchInfo<Label>& info, |
| 7692 | uint64_t index_in_table) const { |
| 7693 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7694 | uintptr_t address = |
| 7695 | 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] | 7696 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7697 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7698 | dchecked_integral_cast<uint32_t>(address); |
| 7699 | } |
| 7700 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7701 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7702 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7703 | 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] | 7704 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7705 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7706 | } |
| 7707 | |
| 7708 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7709 | 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] | 7710 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7711 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7712 | } |
| 7713 | } |
| 7714 | |
Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 7715 | bool LocationsBuilderX86_64::CpuHasAvxFeatureFlag() { |
| 7716 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 7717 | } |
| 7718 | |
| 7719 | bool LocationsBuilderX86_64::CpuHasAvx2FeatureFlag() { |
| 7720 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 7721 | } |
| 7722 | |
| 7723 | bool InstructionCodeGeneratorX86_64::CpuHasAvxFeatureFlag() { |
| 7724 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 7725 | } |
| 7726 | |
| 7727 | bool InstructionCodeGeneratorX86_64::CpuHasAvx2FeatureFlag() { |
| 7728 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 7729 | } |
| 7730 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7731 | #undef __ |
| 7732 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7733 | } // namespace x86_64 |
| 7734 | } // namespace art |