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 | |
| 1074 | MaybeGenerateInlineCacheCheck(invoke->GetDexPc(), temp); |
| 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 | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2528 | void CodeGeneratorX86_64::MaybeGenerateInlineCacheCheck(uint32_t dex_pc, CpuRegister klass) { |
| 2529 | DCHECK_EQ(RDI, klass.AsRegister()); |
| 2530 | if (GetCompilerOptions().IsBaseline() && !Runtime::Current()->IsAotCompiler()) { |
| 2531 | ScopedObjectAccess soa(Thread::Current()); |
| 2532 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
| 2533 | InlineCache* cache = info->GetInlineCache(dex_pc); |
| 2534 | uint64_t address = reinterpret_cast64<uint64_t>(cache); |
| 2535 | NearLabel done; |
| 2536 | __ movq(CpuRegister(TMP), Immediate(address)); |
| 2537 | // Fast path for a monomorphic cache. |
| 2538 | __ cmpl(Address(CpuRegister(TMP), InlineCache::ClassesOffset().Int32Value()), klass); |
| 2539 | __ j(kEqual, &done); |
| 2540 | GenerateInvokeRuntime( |
| 2541 | GetThreadOffset<kX86_64PointerSize>(kQuickUpdateInlineCache).Int32Value()); |
| 2542 | __ Bind(&done); |
| 2543 | } |
| 2544 | } |
| 2545 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2546 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2547 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2548 | LocationSummary* locations = invoke->GetLocations(); |
| 2549 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2550 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2551 | Location receiver = locations->InAt(0); |
| 2552 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2553 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2554 | if (receiver.IsStackSlot()) { |
| 2555 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2556 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2557 | __ movl(temp, Address(temp, class_offset)); |
| 2558 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2559 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2560 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2561 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2562 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2563 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2564 | // emit a read barrier for the previous class reference load. |
| 2565 | // However this is not required in practice, as this is an |
| 2566 | // intermediate/temporary reference and because the current |
| 2567 | // concurrent copying collector keeps the from-space memory |
| 2568 | // intact/accessible until the end of the marking phase (the |
| 2569 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2570 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 2571 | |
| 2572 | codegen_->MaybeGenerateInlineCacheCheck(invoke->GetDexPc(), temp); |
| 2573 | |
| 2574 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2575 | // won't be modified thereafter, before the `call` instruction. |
| 2576 | // We also di it after MaybeGenerateInlineCache that may use RAX. |
| 2577 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
| 2578 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
| 2579 | |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2580 | // temp = temp->GetAddressOfIMT() |
| 2581 | __ movq(temp, |
| 2582 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2583 | // temp = temp->GetImtEntryAt(method_offset); |
| 2584 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2585 | invoke->GetImtIndex(), kX86_64PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2586 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2587 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2588 | // call temp->GetEntryPoint(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2589 | __ call(Address( |
| 2590 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2591 | |
| 2592 | DCHECK(!codegen_->IsLeafMethod()); |
| 2593 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2594 | } |
| 2595 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2596 | void LocationsBuilderX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2597 | HandleInvoke(invoke); |
| 2598 | } |
| 2599 | |
| 2600 | void InstructionCodeGeneratorX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2601 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2602 | } |
| 2603 | |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2604 | void LocationsBuilderX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2605 | HandleInvoke(invoke); |
| 2606 | } |
| 2607 | |
| 2608 | void InstructionCodeGeneratorX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2609 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2610 | } |
| 2611 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2612 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2613 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2614 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2615 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2616 | case DataType::Type::kInt32: |
| 2617 | case DataType::Type::kInt64: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2618 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2619 | locations->SetOut(Location::SameAsFirstInput()); |
| 2620 | break; |
| 2621 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2622 | case DataType::Type::kFloat32: |
| 2623 | case DataType::Type::kFloat64: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2624 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2625 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2626 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2627 | break; |
| 2628 | |
| 2629 | default: |
| 2630 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2631 | } |
| 2632 | } |
| 2633 | |
| 2634 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2635 | LocationSummary* locations = neg->GetLocations(); |
| 2636 | Location out = locations->Out(); |
| 2637 | Location in = locations->InAt(0); |
| 2638 | switch (neg->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2639 | case DataType::Type::kInt32: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2640 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2641 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2642 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2643 | break; |
| 2644 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2645 | case DataType::Type::kInt64: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2646 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2647 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2648 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2649 | break; |
| 2650 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2651 | case DataType::Type::kFloat32: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2652 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2653 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2654 | // Implement float negation with an exclusive or with value |
| 2655 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2656 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2657 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2658 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2659 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2660 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2661 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2662 | case DataType::Type::kFloat64: { |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2663 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2664 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2665 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2666 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2667 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2668 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2669 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2670 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2671 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2672 | |
| 2673 | default: |
| 2674 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2675 | } |
| 2676 | } |
| 2677 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2678 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2679 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2680 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2681 | DataType::Type result_type = conversion->GetResultType(); |
| 2682 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2683 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2684 | << input_type << " -> " << result_type; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2685 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2686 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2687 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2688 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2689 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2690 | case DataType::Type::kInt16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2691 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2692 | locations->SetInAt(0, Location::Any()); |
| 2693 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2694 | break; |
| 2695 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2696 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2697 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2698 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2699 | locations->SetInAt(0, Location::Any()); |
| 2700 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2701 | break; |
| 2702 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2703 | case DataType::Type::kFloat32: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2704 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2705 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2706 | break; |
| 2707 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2708 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2709 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2710 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2711 | break; |
| 2712 | |
| 2713 | default: |
| 2714 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2715 | << " to " << result_type; |
| 2716 | } |
| 2717 | break; |
| 2718 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2719 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2720 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2721 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2722 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2723 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2724 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2725 | case DataType::Type::kInt16: |
| 2726 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2727 | // TODO: We would benefit from a (to-be-implemented) |
| 2728 | // Location::RegisterOrStackSlot requirement for this input. |
| 2729 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2730 | locations->SetOut(Location::RequiresRegister()); |
| 2731 | break; |
| 2732 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2733 | case DataType::Type::kFloat32: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2734 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2735 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2736 | break; |
| 2737 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2738 | case DataType::Type::kFloat64: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2739 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2740 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2741 | break; |
| 2742 | |
| 2743 | default: |
| 2744 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2745 | << " to " << result_type; |
| 2746 | } |
| 2747 | break; |
| 2748 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2749 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2750 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2751 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2752 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2753 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2754 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2755 | case DataType::Type::kInt16: |
| 2756 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2757 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2758 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2759 | break; |
| 2760 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2761 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2762 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +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::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2767 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2768 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2769 | break; |
| 2770 | |
| 2771 | default: |
| 2772 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2773 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2774 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2775 | break; |
| 2776 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2777 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2778 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2779 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2780 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2781 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2782 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2783 | case DataType::Type::kInt16: |
| 2784 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2785 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2786 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2787 | break; |
| 2788 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2789 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2790 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +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::kFloat32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2795 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2796 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2797 | break; |
| 2798 | |
| 2799 | default: |
| 2800 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2801 | << " to " << result_type; |
| 2802 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2803 | break; |
| 2804 | |
| 2805 | default: |
| 2806 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2807 | << " to " << result_type; |
| 2808 | } |
| 2809 | } |
| 2810 | |
| 2811 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2812 | LocationSummary* locations = conversion->GetLocations(); |
| 2813 | Location out = locations->Out(); |
| 2814 | Location in = locations->InAt(0); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2815 | DataType::Type result_type = conversion->GetResultType(); |
| 2816 | DataType::Type input_type = conversion->GetInputType(); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2817 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2818 | << input_type << " -> " << result_type; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2819 | switch (result_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2820 | case DataType::Type::kUint8: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2821 | switch (input_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2822 | case DataType::Type::kInt8: |
| 2823 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2824 | case DataType::Type::kInt16: |
| 2825 | case DataType::Type::kInt32: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2826 | case DataType::Type::kInt64: |
| 2827 | if (in.IsRegister()) { |
| 2828 | __ movzxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 2829 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 2830 | __ movzxb(out.AsRegister<CpuRegister>(), |
| 2831 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2832 | } else { |
| 2833 | __ movl(out.AsRegister<CpuRegister>(), |
| 2834 | Immediate(static_cast<uint8_t>(Int64FromConstant(in.GetConstant())))); |
| 2835 | } |
| 2836 | break; |
| 2837 | |
| 2838 | default: |
| 2839 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2840 | << " to " << result_type; |
| 2841 | } |
| 2842 | break; |
| 2843 | |
| 2844 | case DataType::Type::kInt8: |
| 2845 | switch (input_type) { |
| 2846 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2847 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2848 | case DataType::Type::kInt16: |
| 2849 | case DataType::Type::kInt32: |
| 2850 | case DataType::Type::kInt64: |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2851 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2852 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2853 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2854 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2855 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2856 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2857 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2858 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2859 | } |
| 2860 | break; |
| 2861 | |
| 2862 | default: |
| 2863 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2864 | << " to " << result_type; |
| 2865 | } |
| 2866 | break; |
| 2867 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2868 | case DataType::Type::kUint16: |
| 2869 | switch (input_type) { |
| 2870 | case DataType::Type::kInt8: |
| 2871 | case DataType::Type::kInt16: |
| 2872 | case DataType::Type::kInt32: |
| 2873 | case DataType::Type::kInt64: |
| 2874 | if (in.IsRegister()) { |
| 2875 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 2876 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 2877 | __ movzxw(out.AsRegister<CpuRegister>(), |
| 2878 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2879 | } else { |
| 2880 | __ movl(out.AsRegister<CpuRegister>(), |
| 2881 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
| 2882 | } |
| 2883 | break; |
| 2884 | |
| 2885 | default: |
| 2886 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2887 | << " to " << result_type; |
| 2888 | } |
| 2889 | break; |
| 2890 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2891 | case DataType::Type::kInt16: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2892 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2893 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2894 | case DataType::Type::kInt32: |
| 2895 | case DataType::Type::kInt64: |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2896 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2897 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2898 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2899 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2900 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2901 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2902 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2903 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2904 | } |
| 2905 | break; |
| 2906 | |
| 2907 | default: |
| 2908 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2909 | << " to " << result_type; |
| 2910 | } |
| 2911 | break; |
| 2912 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2913 | case DataType::Type::kInt32: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2914 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2915 | case DataType::Type::kInt64: |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2916 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2917 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2918 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2919 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2920 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2921 | } else { |
| 2922 | DCHECK(in.IsConstant()); |
| 2923 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2924 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2925 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2926 | } |
| 2927 | break; |
| 2928 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2929 | case DataType::Type::kFloat32: { |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2930 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2931 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2932 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2933 | |
| 2934 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2935 | // if input >= (float)INT_MAX goto done |
Nick Desaulniers | 98e97c6 | 2019-10-18 14:25:19 -0700 | [diff] [blame] | 2936 | __ comiss(input, codegen_->LiteralFloatAddress(static_cast<float>(kPrimIntMax))); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2937 | __ j(kAboveEqual, &done); |
| 2938 | // if input == NaN goto nan |
| 2939 | __ j(kUnordered, &nan); |
| 2940 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2941 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2942 | __ jmp(&done); |
| 2943 | __ Bind(&nan); |
| 2944 | // output = 0 |
| 2945 | __ xorl(output, output); |
| 2946 | __ Bind(&done); |
| 2947 | break; |
| 2948 | } |
| 2949 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2950 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2951 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2952 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2953 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2954 | |
| 2955 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2956 | // if input >= (double)INT_MAX goto done |
| 2957 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2958 | __ j(kAboveEqual, &done); |
| 2959 | // if input == NaN goto nan |
| 2960 | __ j(kUnordered, &nan); |
| 2961 | // output = double-to-int-truncate(input) |
| 2962 | __ cvttsd2si(output, input); |
| 2963 | __ jmp(&done); |
| 2964 | __ Bind(&nan); |
| 2965 | // output = 0 |
| 2966 | __ xorl(output, output); |
| 2967 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2968 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2969 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2970 | |
| 2971 | default: |
| 2972 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2973 | << " to " << result_type; |
| 2974 | } |
| 2975 | break; |
| 2976 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2977 | case DataType::Type::kInt64: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2978 | switch (input_type) { |
| 2979 | DCHECK(out.IsRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2980 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2981 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2982 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2983 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2984 | case DataType::Type::kInt16: |
| 2985 | case DataType::Type::kInt32: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2986 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2987 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2988 | break; |
| 2989 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2990 | case DataType::Type::kFloat32: { |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2991 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2992 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2993 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2994 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2995 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2996 | // if input >= (float)LONG_MAX goto done |
Nick Desaulniers | 98e97c6 | 2019-10-18 14:25:19 -0700 | [diff] [blame] | 2997 | __ comiss(input, codegen_->LiteralFloatAddress(static_cast<float>(kPrimLongMax))); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2998 | __ j(kAboveEqual, &done); |
| 2999 | // if input == NaN goto nan |
| 3000 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3001 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3002 | __ cvttss2si(output, input, true); |
| 3003 | __ jmp(&done); |
| 3004 | __ Bind(&nan); |
| 3005 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3006 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3007 | __ Bind(&done); |
| 3008 | break; |
| 3009 | } |
| 3010 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3011 | case DataType::Type::kFloat64: { |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3012 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 3013 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3014 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3015 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3016 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 3017 | // if input >= (double)LONG_MAX goto done |
Nick Desaulniers | 98e97c6 | 2019-10-18 14:25:19 -0700 | [diff] [blame] | 3018 | __ comisd(input, codegen_->LiteralDoubleAddress( |
| 3019 | static_cast<double>(kPrimLongMax))); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3020 | __ j(kAboveEqual, &done); |
| 3021 | // if input == NaN goto nan |
| 3022 | __ j(kUnordered, &nan); |
| 3023 | // output = double-to-long-truncate(input) |
| 3024 | __ cvttsd2si(output, input, true); |
| 3025 | __ jmp(&done); |
| 3026 | __ Bind(&nan); |
| 3027 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3028 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3029 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3030 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 3031 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3032 | |
| 3033 | default: |
| 3034 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3035 | << " to " << result_type; |
| 3036 | } |
| 3037 | break; |
| 3038 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3039 | case DataType::Type::kFloat32: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3040 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3041 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3042 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3043 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3044 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3045 | case DataType::Type::kInt16: |
| 3046 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3047 | if (in.IsRegister()) { |
| 3048 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3049 | } else if (in.IsConstant()) { |
| 3050 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3051 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3052 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3053 | } else { |
| 3054 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3055 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3056 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3057 | break; |
| 3058 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3059 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3060 | if (in.IsRegister()) { |
| 3061 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3062 | } else if (in.IsConstant()) { |
| 3063 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3064 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 3065 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3066 | } else { |
| 3067 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3068 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3069 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3070 | break; |
| 3071 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3072 | case DataType::Type::kFloat64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3073 | if (in.IsFpuRegister()) { |
| 3074 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3075 | } else if (in.IsConstant()) { |
| 3076 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 3077 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3078 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3079 | } else { |
| 3080 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 3081 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3082 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3083 | break; |
| 3084 | |
| 3085 | default: |
| 3086 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3087 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3088 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3089 | break; |
| 3090 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3091 | case DataType::Type::kFloat64: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3092 | switch (input_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3093 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3094 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3095 | case DataType::Type::kInt8: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3096 | case DataType::Type::kUint16: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3097 | case DataType::Type::kInt16: |
| 3098 | case DataType::Type::kInt32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3099 | if (in.IsRegister()) { |
| 3100 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3101 | } else if (in.IsConstant()) { |
| 3102 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3103 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3104 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3105 | } else { |
| 3106 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3107 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3108 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3109 | break; |
| 3110 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3111 | case DataType::Type::kInt64: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3112 | if (in.IsRegister()) { |
| 3113 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3114 | } else if (in.IsConstant()) { |
| 3115 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3116 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3117 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3118 | } else { |
| 3119 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3120 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3121 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3122 | break; |
| 3123 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3124 | case DataType::Type::kFloat32: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3125 | if (in.IsFpuRegister()) { |
| 3126 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3127 | } else if (in.IsConstant()) { |
| 3128 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3129 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3130 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3131 | } else { |
| 3132 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3133 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3134 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3135 | break; |
| 3136 | |
| 3137 | default: |
| 3138 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3139 | << " to " << result_type; |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3140 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3141 | break; |
| 3142 | |
| 3143 | default: |
| 3144 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3145 | << " to " << result_type; |
| 3146 | } |
| 3147 | } |
| 3148 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3149 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3150 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3151 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3152 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3153 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3154 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3155 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3156 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3157 | break; |
| 3158 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3159 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3160 | case DataType::Type::kInt64: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3161 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3162 | // 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] | 3163 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3164 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3165 | break; |
| 3166 | } |
| 3167 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3168 | case DataType::Type::kFloat64: |
| 3169 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3170 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3171 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3172 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3173 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3174 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3175 | |
| 3176 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3177 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3178 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3182 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3183 | Location first = locations->InAt(0); |
| 3184 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3185 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3186 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3187 | switch (add->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3188 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3189 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3190 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3191 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3192 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3193 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3194 | } else { |
| 3195 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3196 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3197 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3198 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3199 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3200 | __ addl(out.AsRegister<CpuRegister>(), |
| 3201 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3202 | } else { |
| 3203 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3204 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3205 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3206 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3207 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3208 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3209 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3210 | break; |
| 3211 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3212 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3213 | case DataType::Type::kInt64: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3214 | if (second.IsRegister()) { |
| 3215 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3216 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3217 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3218 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3219 | } else { |
| 3220 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3221 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3222 | } |
| 3223 | } else { |
| 3224 | DCHECK(second.IsConstant()); |
| 3225 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3226 | int32_t int32_value = Low32Bits(value); |
| 3227 | DCHECK_EQ(int32_value, value); |
| 3228 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3229 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3230 | } else { |
| 3231 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3232 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3233 | } |
| 3234 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3235 | break; |
| 3236 | } |
| 3237 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3238 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3239 | if (second.IsFpuRegister()) { |
| 3240 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3241 | } else if (second.IsConstant()) { |
| 3242 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3243 | codegen_->LiteralFloatAddress( |
| 3244 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3245 | } else { |
| 3246 | DCHECK(second.IsStackSlot()); |
| 3247 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3248 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3249 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3250 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3251 | } |
| 3252 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3253 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3254 | if (second.IsFpuRegister()) { |
| 3255 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3256 | } else if (second.IsConstant()) { |
| 3257 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3258 | codegen_->LiteralDoubleAddress( |
| 3259 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3260 | } else { |
| 3261 | DCHECK(second.IsDoubleStackSlot()); |
| 3262 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3263 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3264 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3265 | break; |
| 3266 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3267 | |
| 3268 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3269 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3270 | } |
| 3271 | } |
| 3272 | |
| 3273 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3274 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3275 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3276 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3277 | case DataType::Type::kInt32: { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3278 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3279 | locations->SetInAt(1, Location::Any()); |
| 3280 | locations->SetOut(Location::SameAsFirstInput()); |
| 3281 | break; |
| 3282 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3283 | case DataType::Type::kInt64: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3284 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3285 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3286 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3287 | break; |
| 3288 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3289 | case DataType::Type::kFloat32: |
| 3290 | case DataType::Type::kFloat64: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3291 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3292 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3293 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3294 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3295 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3296 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3297 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3298 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3302 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3303 | Location first = locations->InAt(0); |
| 3304 | Location second = locations->InAt(1); |
| 3305 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3306 | switch (sub->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3307 | case DataType::Type::kInt32: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3308 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3309 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3310 | } else if (second.IsConstant()) { |
| 3311 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3312 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3313 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3314 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3315 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3316 | break; |
| 3317 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3318 | case DataType::Type::kInt64: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3319 | if (second.IsConstant()) { |
| 3320 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3321 | DCHECK(IsInt<32>(value)); |
| 3322 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3323 | } else { |
| 3324 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3325 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3326 | break; |
| 3327 | } |
| 3328 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3329 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3330 | if (second.IsFpuRegister()) { |
| 3331 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3332 | } else if (second.IsConstant()) { |
| 3333 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3334 | codegen_->LiteralFloatAddress( |
| 3335 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3336 | } else { |
| 3337 | DCHECK(second.IsStackSlot()); |
| 3338 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3339 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3340 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3341 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3342 | } |
| 3343 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3344 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3345 | if (second.IsFpuRegister()) { |
| 3346 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3347 | } else if (second.IsConstant()) { |
| 3348 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3349 | codegen_->LiteralDoubleAddress( |
| 3350 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3351 | } else { |
| 3352 | DCHECK(second.IsDoubleStackSlot()); |
| 3353 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3354 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3355 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3356 | break; |
| 3357 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3358 | |
| 3359 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3360 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3361 | } |
| 3362 | } |
| 3363 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3364 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3365 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3366 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3367 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3368 | case DataType::Type::kInt32: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3369 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3370 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3371 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3372 | // Can use 3 operand multiply. |
| 3373 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3374 | } else { |
| 3375 | locations->SetOut(Location::SameAsFirstInput()); |
| 3376 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3377 | break; |
| 3378 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3379 | case DataType::Type::kInt64: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3380 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3381 | locations->SetInAt(1, Location::Any()); |
| 3382 | if (mul->InputAt(1)->IsLongConstant() && |
| 3383 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3384 | // Can use 3 operand multiply. |
| 3385 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3386 | } else { |
| 3387 | locations->SetOut(Location::SameAsFirstInput()); |
| 3388 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3389 | break; |
| 3390 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3391 | case DataType::Type::kFloat32: |
| 3392 | case DataType::Type::kFloat64: { |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3393 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3394 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3395 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3396 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3397 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3398 | |
| 3399 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3400 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3401 | } |
| 3402 | } |
| 3403 | |
| 3404 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3405 | LocationSummary* locations = mul->GetLocations(); |
| 3406 | Location first = locations->InAt(0); |
| 3407 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3408 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3409 | switch (mul->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3410 | case DataType::Type::kInt32: |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3411 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3412 | // problems where the output may not be the same as the first operand. |
| 3413 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3414 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3415 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3416 | } else if (second.IsRegister()) { |
| 3417 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3418 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3419 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3420 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3421 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3422 | __ imull(first.AsRegister<CpuRegister>(), |
| 3423 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3424 | } |
| 3425 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3426 | case DataType::Type::kInt64: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3427 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3428 | // problems where the output may not be the same as the first operand. |
| 3429 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3430 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3431 | if (IsInt<32>(value)) { |
| 3432 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3433 | Immediate(static_cast<int32_t>(value))); |
| 3434 | } else { |
| 3435 | // Have to use the constant area. |
| 3436 | DCHECK(first.Equals(out)); |
| 3437 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3438 | } |
| 3439 | } else if (second.IsRegister()) { |
| 3440 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3441 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3442 | } else { |
| 3443 | DCHECK(second.IsDoubleStackSlot()); |
| 3444 | DCHECK(first.Equals(out)); |
| 3445 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3446 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3447 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3448 | break; |
| 3449 | } |
| 3450 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3451 | case DataType::Type::kFloat32: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3452 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3453 | if (second.IsFpuRegister()) { |
| 3454 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3455 | } else if (second.IsConstant()) { |
| 3456 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3457 | codegen_->LiteralFloatAddress( |
| 3458 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3459 | } else { |
| 3460 | DCHECK(second.IsStackSlot()); |
| 3461 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3462 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3463 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3464 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3465 | } |
| 3466 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3467 | case DataType::Type::kFloat64: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3468 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3469 | if (second.IsFpuRegister()) { |
| 3470 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3471 | } else if (second.IsConstant()) { |
| 3472 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3473 | codegen_->LiteralDoubleAddress( |
| 3474 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3475 | } else { |
| 3476 | DCHECK(second.IsDoubleStackSlot()); |
| 3477 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3478 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3479 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3480 | break; |
| 3481 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3482 | |
| 3483 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3484 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3485 | } |
| 3486 | } |
| 3487 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3488 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3489 | uint32_t stack_adjustment, bool is_float) { |
| 3490 | if (source.IsStackSlot()) { |
| 3491 | DCHECK(is_float); |
| 3492 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3493 | } else if (source.IsDoubleStackSlot()) { |
| 3494 | DCHECK(!is_float); |
| 3495 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3496 | } else { |
| 3497 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3498 | if (is_float) { |
| 3499 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3500 | codegen_->Move(stack_temp, source); |
| 3501 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3502 | } else { |
| 3503 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3504 | codegen_->Move(stack_temp, source); |
| 3505 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3506 | } |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3511 | DataType::Type type = rem->GetResultType(); |
| 3512 | bool is_float = type == DataType::Type::kFloat32; |
| 3513 | size_t elem_size = DataType::Size(type); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3514 | LocationSummary* locations = rem->GetLocations(); |
| 3515 | Location first = locations->InAt(0); |
| 3516 | Location second = locations->InAt(1); |
| 3517 | Location out = locations->Out(); |
| 3518 | |
| 3519 | // Create stack space for 2 elements. |
| 3520 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3521 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3522 | |
| 3523 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3524 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3525 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3526 | |
| 3527 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3528 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3529 | __ Bind(&retry); |
| 3530 | __ fprem(); |
| 3531 | |
| 3532 | // Move FP status to AX. |
| 3533 | __ fstsw(); |
| 3534 | |
| 3535 | // And see if the argument reduction is complete. This is signaled by the |
| 3536 | // C2 FPU flag bit set to 0. |
| 3537 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3538 | __ j(kNotEqual, &retry); |
| 3539 | |
| 3540 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3541 | // Store FP top of stack to real stack. |
| 3542 | if (is_float) { |
| 3543 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3544 | } else { |
| 3545 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3546 | } |
| 3547 | |
| 3548 | // Pop the 2 items from the FP stack. |
| 3549 | __ fucompp(); |
| 3550 | |
| 3551 | // Load the value from the stack into an XMM register. |
| 3552 | DCHECK(out.IsFpuRegister()) << out; |
| 3553 | if (is_float) { |
| 3554 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3555 | } else { |
| 3556 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3557 | } |
| 3558 | |
| 3559 | // And remove the temporary stack space we allocated. |
| 3560 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3561 | } |
| 3562 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3563 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3564 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3565 | |
| 3566 | LocationSummary* locations = instruction->GetLocations(); |
| 3567 | Location second = locations->InAt(1); |
| 3568 | DCHECK(second.IsConstant()); |
| 3569 | |
| 3570 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3571 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3572 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3573 | |
| 3574 | DCHECK(imm == 1 || imm == -1); |
| 3575 | |
| 3576 | switch (instruction->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3577 | case DataType::Type::kInt32: { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3578 | if (instruction->IsRem()) { |
| 3579 | __ xorl(output_register, output_register); |
| 3580 | } else { |
| 3581 | __ movl(output_register, input_register); |
| 3582 | if (imm == -1) { |
| 3583 | __ negl(output_register); |
| 3584 | } |
| 3585 | } |
| 3586 | break; |
| 3587 | } |
| 3588 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3589 | case DataType::Type::kInt64: { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3590 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3591 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3592 | } else { |
| 3593 | __ movq(output_register, input_register); |
| 3594 | if (imm == -1) { |
| 3595 | __ negq(output_register); |
| 3596 | } |
| 3597 | } |
| 3598 | break; |
| 3599 | } |
| 3600 | |
| 3601 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3602 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3603 | } |
| 3604 | } |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3605 | void InstructionCodeGeneratorX86_64::RemByPowerOfTwo(HRem* instruction) { |
| 3606 | LocationSummary* locations = instruction->GetLocations(); |
| 3607 | Location second = locations->InAt(1); |
| 3608 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3609 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3610 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| 3611 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3612 | uint64_t abs_imm = AbsOrMin(imm); |
| 3613 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3614 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| 3615 | NearLabel done; |
| 3616 | __ movl(out, numerator); |
| 3617 | __ andl(out, Immediate(abs_imm-1)); |
| 3618 | __ j(Condition::kZero, &done); |
| 3619 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); |
| 3620 | __ testl(numerator, numerator); |
| 3621 | __ cmov(Condition::kLess, out, tmp, false); |
| 3622 | __ Bind(&done); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3623 | |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3624 | } else { |
| 3625 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| 3626 | codegen_->Load64BitValue(tmp, abs_imm - 1); |
| 3627 | NearLabel done; |
| 3628 | |
| 3629 | __ movq(out, numerator); |
| 3630 | __ andq(out, tmp); |
| 3631 | __ j(Condition::kZero, &done); |
| 3632 | __ movq(tmp, numerator); |
| 3633 | __ sarq(tmp, Immediate(63)); |
| 3634 | __ shlq(tmp, Immediate(WhichPowerOf2(abs_imm))); |
| 3635 | __ orq(out, tmp); |
| 3636 | __ Bind(&done); |
| 3637 | } |
| 3638 | } |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3639 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3640 | LocationSummary* locations = instruction->GetLocations(); |
| 3641 | Location second = locations->InAt(1); |
| 3642 | |
| 3643 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3644 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3645 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3646 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3647 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3648 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3649 | |
| 3650 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3651 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3652 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 3653 | // When denominator is equal to 2, we can add signed bit and numerator to tmp. |
| 3654 | // Below we are using addl instruction instead of cmov which give us 1 cycle benefit. |
| 3655 | if (abs_imm == 2) { |
| 3656 | __ leal(tmp, Address(numerator, 0)); |
| 3657 | __ shrl(tmp, Immediate(31)); |
| 3658 | __ addl(tmp, numerator); |
| 3659 | } else { |
| 3660 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
| 3661 | __ testl(numerator, numerator); |
| 3662 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3663 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3664 | int shift = CTZ(imm); |
| 3665 | __ sarl(tmp, Immediate(shift)); |
| 3666 | |
| 3667 | if (imm < 0) { |
| 3668 | __ negl(tmp); |
| 3669 | } |
| 3670 | |
| 3671 | __ movl(output_register, tmp); |
| 3672 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3673 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3674 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 3675 | if (abs_imm == 2) { |
| 3676 | __ movq(rdx, numerator); |
| 3677 | __ shrq(rdx, Immediate(63)); |
| 3678 | __ addq(rdx, numerator); |
| 3679 | } else { |
| 3680 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
| 3681 | __ addq(rdx, numerator); |
| 3682 | __ testq(numerator, numerator); |
| 3683 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3684 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3685 | int shift = CTZ(imm); |
| 3686 | __ sarq(rdx, Immediate(shift)); |
| 3687 | |
| 3688 | if (imm < 0) { |
| 3689 | __ negq(rdx); |
| 3690 | } |
| 3691 | |
| 3692 | __ movq(output_register, rdx); |
| 3693 | } |
| 3694 | } |
| 3695 | |
| 3696 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3697 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3698 | |
| 3699 | LocationSummary* locations = instruction->GetLocations(); |
| 3700 | Location second = locations->InAt(1); |
| 3701 | |
| 3702 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3703 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3704 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3705 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3706 | : locations->Out().AsRegister<CpuRegister>(); |
| 3707 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3708 | |
| 3709 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3710 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3711 | if (instruction->IsDiv()) { |
| 3712 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3713 | } else { |
| 3714 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3715 | } |
| 3716 | |
| 3717 | int64_t magic; |
| 3718 | int shift; |
| 3719 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3720 | // TODO: can these branches be written as one? |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3721 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3722 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3723 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3724 | CalculateMagicAndShiftForDivRem(imm, false /* is_long= */, &magic, &shift); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3725 | |
| 3726 | __ movl(numerator, eax); |
| 3727 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3728 | __ movl(eax, Immediate(magic)); |
| 3729 | __ imull(numerator); |
| 3730 | |
| 3731 | if (imm > 0 && magic < 0) { |
| 3732 | __ addl(edx, numerator); |
| 3733 | } else if (imm < 0 && magic > 0) { |
| 3734 | __ subl(edx, numerator); |
| 3735 | } |
| 3736 | |
| 3737 | if (shift != 0) { |
| 3738 | __ sarl(edx, Immediate(shift)); |
| 3739 | } |
| 3740 | |
| 3741 | __ movl(eax, edx); |
| 3742 | __ shrl(edx, Immediate(31)); |
| 3743 | __ addl(edx, eax); |
| 3744 | |
| 3745 | if (instruction->IsRem()) { |
| 3746 | __ movl(eax, numerator); |
| 3747 | __ imull(edx, Immediate(imm)); |
| 3748 | __ subl(eax, edx); |
| 3749 | __ movl(edx, eax); |
| 3750 | } else { |
| 3751 | __ movl(eax, edx); |
| 3752 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3753 | } else { |
| 3754 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3755 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3756 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3757 | |
| 3758 | CpuRegister rax = eax; |
| 3759 | CpuRegister rdx = edx; |
| 3760 | |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3761 | CalculateMagicAndShiftForDivRem(imm, true /* is_long= */, &magic, &shift); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3762 | |
| 3763 | // Save the numerator. |
| 3764 | __ movq(numerator, rax); |
| 3765 | |
| 3766 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3767 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3768 | |
| 3769 | // RDX:RAX = magic * numerator |
| 3770 | __ imulq(numerator); |
| 3771 | |
| 3772 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3773 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3774 | __ addq(rdx, numerator); |
| 3775 | } else if (imm < 0 && magic > 0) { |
| 3776 | // RDX -= numerator |
| 3777 | __ subq(rdx, numerator); |
| 3778 | } |
| 3779 | |
| 3780 | // Shift if needed. |
| 3781 | if (shift != 0) { |
| 3782 | __ sarq(rdx, Immediate(shift)); |
| 3783 | } |
| 3784 | |
| 3785 | // RDX += 1 if RDX < 0 |
| 3786 | __ movq(rax, rdx); |
| 3787 | __ shrq(rdx, Immediate(63)); |
| 3788 | __ addq(rdx, rax); |
| 3789 | |
| 3790 | if (instruction->IsRem()) { |
| 3791 | __ movq(rax, numerator); |
| 3792 | |
| 3793 | if (IsInt<32>(imm)) { |
| 3794 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3795 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3796 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | __ subq(rax, rdx); |
| 3800 | __ movq(rdx, rax); |
| 3801 | } else { |
| 3802 | __ movq(rax, rdx); |
| 3803 | } |
| 3804 | } |
| 3805 | } |
| 3806 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3807 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3808 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3809 | DataType::Type type = instruction->GetResultType(); |
| 3810 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3811 | |
| 3812 | bool is_div = instruction->IsDiv(); |
| 3813 | LocationSummary* locations = instruction->GetLocations(); |
| 3814 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3815 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3816 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3817 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3818 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3819 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3820 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3821 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3822 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3823 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3824 | if (imm == 0) { |
| 3825 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3826 | } else if (imm == 1 || imm == -1) { |
| 3827 | DivRemOneOrMinusOne(instruction); |
Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3828 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 3829 | if (is_div) { |
| 3830 | DivByPowerOfTwo(instruction->AsDiv()); |
| 3831 | } else { |
| 3832 | RemByPowerOfTwo(instruction->AsRem()); |
| 3833 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3834 | } else { |
| 3835 | DCHECK(imm <= -2 || imm >= 2); |
| 3836 | GenerateDivRemWithAnyConstant(instruction); |
| 3837 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3838 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3839 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3840 | new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3841 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3842 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3843 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3844 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3845 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3846 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3847 | // 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] | 3848 | if (type == DataType::Type::kInt32) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3849 | __ cmpl(second_reg, Immediate(-1)); |
| 3850 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3851 | // edx:eax <- sign-extended of eax |
| 3852 | __ cdq(); |
| 3853 | // eax = quotient, edx = remainder |
| 3854 | __ idivl(second_reg); |
| 3855 | } else { |
| 3856 | __ cmpq(second_reg, Immediate(-1)); |
| 3857 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3858 | // rdx:rax <- sign-extended of rax |
| 3859 | __ cqo(); |
| 3860 | // rax = quotient, rdx = remainder |
| 3861 | __ idivq(second_reg); |
| 3862 | } |
| 3863 | __ Bind(slow_path->GetExitLabel()); |
| 3864 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3867 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3868 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3869 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3870 | switch (div->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3871 | case DataType::Type::kInt32: |
| 3872 | case DataType::Type::kInt64: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3873 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3874 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3875 | locations->SetOut(Location::SameAsFirstInput()); |
| 3876 | // Intel uses edx:eax as the dividend. |
| 3877 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3878 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3879 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3880 | // output and request another temp. |
| 3881 | if (div->InputAt(1)->IsConstant()) { |
| 3882 | locations->AddTemp(Location::RequiresRegister()); |
| 3883 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3884 | break; |
| 3885 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3886 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3887 | case DataType::Type::kFloat32: |
| 3888 | case DataType::Type::kFloat64: { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3889 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3890 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3891 | locations->SetOut(Location::SameAsFirstInput()); |
| 3892 | break; |
| 3893 | } |
| 3894 | |
| 3895 | default: |
| 3896 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3897 | } |
| 3898 | } |
| 3899 | |
| 3900 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3901 | LocationSummary* locations = div->GetLocations(); |
| 3902 | Location first = locations->InAt(0); |
| 3903 | Location second = locations->InAt(1); |
| 3904 | DCHECK(first.Equals(locations->Out())); |
| 3905 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3906 | DataType::Type type = div->GetResultType(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3907 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3908 | case DataType::Type::kInt32: |
| 3909 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3910 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3911 | break; |
| 3912 | } |
| 3913 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3914 | case DataType::Type::kFloat32: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3915 | if (second.IsFpuRegister()) { |
| 3916 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3917 | } else if (second.IsConstant()) { |
| 3918 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3919 | codegen_->LiteralFloatAddress( |
| 3920 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3921 | } else { |
| 3922 | DCHECK(second.IsStackSlot()); |
| 3923 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3924 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3925 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3926 | break; |
| 3927 | } |
| 3928 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3929 | case DataType::Type::kFloat64: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3930 | if (second.IsFpuRegister()) { |
| 3931 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3932 | } else if (second.IsConstant()) { |
| 3933 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3934 | codegen_->LiteralDoubleAddress( |
| 3935 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3936 | } else { |
| 3937 | DCHECK(second.IsDoubleStackSlot()); |
| 3938 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3939 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3940 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3941 | break; |
| 3942 | } |
| 3943 | |
| 3944 | default: |
| 3945 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3946 | } |
| 3947 | } |
| 3948 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3949 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3950 | DataType::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3951 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3952 | new (GetGraph()->GetAllocator()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3953 | |
| 3954 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3955 | case DataType::Type::kInt32: |
| 3956 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3957 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3958 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3959 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3960 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3961 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3962 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3963 | // output and request another temp. |
| 3964 | if (rem->InputAt(1)->IsConstant()) { |
| 3965 | locations->AddTemp(Location::RequiresRegister()); |
| 3966 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3967 | break; |
| 3968 | } |
| 3969 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3970 | case DataType::Type::kFloat32: |
| 3971 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3972 | locations->SetInAt(0, Location::Any()); |
| 3973 | locations->SetInAt(1, Location::Any()); |
| 3974 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3975 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3976 | break; |
| 3977 | } |
| 3978 | |
| 3979 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3980 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3985 | DataType::Type type = rem->GetResultType(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3986 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3987 | case DataType::Type::kInt32: |
| 3988 | case DataType::Type::kInt64: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3989 | GenerateDivRemIntegral(rem); |
| 3990 | break; |
| 3991 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3992 | case DataType::Type::kFloat32: |
| 3993 | case DataType::Type::kFloat64: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3994 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3995 | break; |
| 3996 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3997 | default: |
| 3998 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3999 | } |
| 4000 | } |
| 4001 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4002 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4003 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4004 | switch (minmax->GetResultType()) { |
| 4005 | case DataType::Type::kInt32: |
| 4006 | case DataType::Type::kInt64: |
| 4007 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4008 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4009 | locations->SetOut(Location::SameAsFirstInput()); |
| 4010 | break; |
| 4011 | case DataType::Type::kFloat32: |
| 4012 | case DataType::Type::kFloat64: |
| 4013 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4014 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4015 | // The following is sub-optimal, but all we can do for now. It would be fine to also accept |
| 4016 | // the second input to be the output (we can simply swap inputs). |
| 4017 | locations->SetOut(Location::SameAsFirstInput()); |
| 4018 | break; |
| 4019 | default: |
| 4020 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4021 | } |
| 4022 | } |
| 4023 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4024 | void InstructionCodeGeneratorX86_64::GenerateMinMaxInt(LocationSummary* locations, |
| 4025 | bool is_min, |
| 4026 | DataType::Type type) { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4027 | Location op1_loc = locations->InAt(0); |
| 4028 | Location op2_loc = locations->InAt(1); |
| 4029 | |
| 4030 | // Shortcut for same input locations. |
| 4031 | if (op1_loc.Equals(op2_loc)) { |
| 4032 | // Can return immediately, as op1_loc == out_loc. |
| 4033 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 4034 | // a copy here. |
| 4035 | DCHECK(locations->Out().Equals(op1_loc)); |
| 4036 | return; |
| 4037 | } |
| 4038 | |
| 4039 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4040 | CpuRegister op2 = op2_loc.AsRegister<CpuRegister>(); |
| 4041 | |
| 4042 | // (out := op1) |
| 4043 | // out <=? op2 |
| 4044 | // if out is min jmp done |
| 4045 | // out := op2 |
| 4046 | // done: |
| 4047 | |
| 4048 | if (type == DataType::Type::kInt64) { |
| 4049 | __ cmpq(out, op2); |
| 4050 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ true); |
| 4051 | } else { |
| 4052 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 4053 | __ cmpl(out, op2); |
| 4054 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ false); |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | void InstructionCodeGeneratorX86_64::GenerateMinMaxFP(LocationSummary* locations, |
| 4059 | bool is_min, |
| 4060 | DataType::Type type) { |
| 4061 | Location op1_loc = locations->InAt(0); |
| 4062 | Location op2_loc = locations->InAt(1); |
| 4063 | Location out_loc = locations->Out(); |
| 4064 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 4065 | |
| 4066 | // Shortcut for same input locations. |
| 4067 | if (op1_loc.Equals(op2_loc)) { |
| 4068 | DCHECK(out_loc.Equals(op1_loc)); |
| 4069 | return; |
| 4070 | } |
| 4071 | |
| 4072 | // (out := op1) |
| 4073 | // out <=? op2 |
| 4074 | // if Nan jmp Nan_label |
| 4075 | // if out is min jmp done |
| 4076 | // if op2 is min jmp op2_label |
| 4077 | // handle -0/+0 |
| 4078 | // jmp done |
| 4079 | // Nan_label: |
| 4080 | // out := NaN |
| 4081 | // op2_label: |
| 4082 | // out := op2 |
| 4083 | // done: |
| 4084 | // |
| 4085 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 4086 | // |
| 4087 | // TODO: This is straight from Quick. Make NaN an out-of-line slowpath? |
| 4088 | |
| 4089 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 4090 | |
| 4091 | NearLabel nan, done, op2_label; |
| 4092 | if (type == DataType::Type::kFloat64) { |
| 4093 | __ ucomisd(out, op2); |
| 4094 | } else { |
| 4095 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 4096 | __ ucomiss(out, op2); |
| 4097 | } |
| 4098 | |
| 4099 | __ j(Condition::kParityEven, &nan); |
| 4100 | |
| 4101 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4102 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4103 | |
| 4104 | // Handle 0.0/-0.0. |
| 4105 | if (is_min) { |
| 4106 | if (type == DataType::Type::kFloat64) { |
| 4107 | __ orpd(out, op2); |
| 4108 | } else { |
| 4109 | __ orps(out, op2); |
| 4110 | } |
| 4111 | } else { |
| 4112 | if (type == DataType::Type::kFloat64) { |
| 4113 | __ andpd(out, op2); |
| 4114 | } else { |
| 4115 | __ andps(out, op2); |
| 4116 | } |
| 4117 | } |
| 4118 | __ jmp(&done); |
| 4119 | |
| 4120 | // NaN handling. |
| 4121 | __ Bind(&nan); |
| 4122 | if (type == DataType::Type::kFloat64) { |
| 4123 | __ movsd(out, codegen_->LiteralInt64Address(INT64_C(0x7FF8000000000000))); |
| 4124 | } else { |
| 4125 | __ movss(out, codegen_->LiteralInt32Address(INT32_C(0x7FC00000))); |
| 4126 | } |
| 4127 | __ jmp(&done); |
| 4128 | |
| 4129 | // out := op2; |
| 4130 | __ Bind(&op2_label); |
| 4131 | if (type == DataType::Type::kFloat64) { |
| 4132 | __ movsd(out, op2); |
| 4133 | } else { |
| 4134 | __ movss(out, op2); |
| 4135 | } |
| 4136 | |
| 4137 | // Done. |
| 4138 | __ Bind(&done); |
| 4139 | } |
| 4140 | |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4141 | void InstructionCodeGeneratorX86_64::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4142 | DataType::Type type = minmax->GetResultType(); |
| 4143 | switch (type) { |
| 4144 | case DataType::Type::kInt32: |
| 4145 | case DataType::Type::kInt64: |
| 4146 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4147 | break; |
| 4148 | case DataType::Type::kFloat32: |
| 4149 | case DataType::Type::kFloat64: |
| 4150 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4151 | break; |
| 4152 | default: |
| 4153 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4154 | } |
| 4155 | } |
| 4156 | |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4157 | void LocationsBuilderX86_64::VisitMin(HMin* min) { |
| 4158 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4159 | } |
| 4160 | |
| 4161 | void InstructionCodeGeneratorX86_64::VisitMin(HMin* min) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4162 | GenerateMinMax(min, /*is_min*/ true); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | void LocationsBuilderX86_64::VisitMax(HMax* max) { |
| 4166 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4167 | } |
| 4168 | |
| 4169 | void InstructionCodeGeneratorX86_64::VisitMax(HMax* max) { |
Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4170 | GenerateMinMax(max, /*is_min*/ false); |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4171 | } |
| 4172 | |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4173 | void LocationsBuilderX86_64::VisitAbs(HAbs* abs) { |
| 4174 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4175 | switch (abs->GetResultType()) { |
| 4176 | case DataType::Type::kInt32: |
| 4177 | case DataType::Type::kInt64: |
| 4178 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4179 | locations->SetOut(Location::SameAsFirstInput()); |
| 4180 | locations->AddTemp(Location::RequiresRegister()); |
| 4181 | break; |
| 4182 | case DataType::Type::kFloat32: |
| 4183 | case DataType::Type::kFloat64: |
| 4184 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4185 | locations->SetOut(Location::SameAsFirstInput()); |
| 4186 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4187 | break; |
| 4188 | default: |
| 4189 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4190 | } |
| 4191 | } |
| 4192 | |
| 4193 | void InstructionCodeGeneratorX86_64::VisitAbs(HAbs* abs) { |
| 4194 | LocationSummary* locations = abs->GetLocations(); |
| 4195 | switch (abs->GetResultType()) { |
| 4196 | case DataType::Type::kInt32: { |
| 4197 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4198 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4199 | // Create mask. |
| 4200 | __ movl(mask, out); |
| 4201 | __ sarl(mask, Immediate(31)); |
| 4202 | // Add mask. |
| 4203 | __ addl(out, mask); |
| 4204 | __ xorl(out, mask); |
| 4205 | break; |
| 4206 | } |
| 4207 | case DataType::Type::kInt64: { |
| 4208 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4209 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4210 | // Create mask. |
| 4211 | __ movq(mask, out); |
| 4212 | __ sarq(mask, Immediate(63)); |
| 4213 | // Add mask. |
| 4214 | __ addq(out, mask); |
| 4215 | __ xorq(out, mask); |
| 4216 | break; |
| 4217 | } |
| 4218 | case DataType::Type::kFloat32: { |
| 4219 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4220 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4221 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x7FFFFFFF))); |
| 4222 | __ andps(out, mask); |
| 4223 | break; |
| 4224 | } |
| 4225 | case DataType::Type::kFloat64: { |
| 4226 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4227 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4228 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x7FFFFFFFFFFFFFFF))); |
| 4229 | __ andpd(out, mask); |
| 4230 | break; |
| 4231 | } |
| 4232 | default: |
| 4233 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4234 | } |
| 4235 | } |
| 4236 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4237 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4238 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4239 | locations->SetInAt(0, Location::Any()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4240 | } |
| 4241 | |
| 4242 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4243 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4244 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86_64(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4245 | codegen_->AddSlowPath(slow_path); |
| 4246 | |
| 4247 | LocationSummary* locations = instruction->GetLocations(); |
| 4248 | Location value = locations->InAt(0); |
| 4249 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4250 | switch (instruction->GetType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4251 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4252 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4253 | case DataType::Type::kInt8: |
| 4254 | case DataType::Type::kUint16: |
| 4255 | case DataType::Type::kInt16: |
| 4256 | case DataType::Type::kInt32: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4257 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4258 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4259 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4260 | } else if (value.IsStackSlot()) { |
| 4261 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4262 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4263 | } else { |
| 4264 | DCHECK(value.IsConstant()) << value; |
| 4265 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4266 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4267 | } |
| 4268 | } |
| 4269 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4270 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4271 | case DataType::Type::kInt64: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4272 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4273 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4274 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4275 | } else if (value.IsDoubleStackSlot()) { |
| 4276 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4277 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4278 | } else { |
| 4279 | DCHECK(value.IsConstant()) << value; |
| 4280 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4281 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4282 | } |
| 4283 | } |
| 4284 | break; |
| 4285 | } |
| 4286 | default: |
| 4287 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4288 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4289 | } |
| 4290 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4291 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 4292 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4293 | |
| 4294 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4295 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4296 | |
| 4297 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4298 | case DataType::Type::kInt32: |
| 4299 | case DataType::Type::kInt64: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4300 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4301 | // The shift count needs to be in CL. |
| 4302 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 4303 | locations->SetOut(Location::SameAsFirstInput()); |
| 4304 | break; |
| 4305 | } |
| 4306 | default: |
| 4307 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 4312 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4313 | |
| 4314 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4315 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4316 | Location second = locations->InAt(1); |
| 4317 | |
| 4318 | switch (op->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4319 | case DataType::Type::kInt32: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4320 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4321 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4322 | if (op->IsShl()) { |
| 4323 | __ shll(first_reg, second_reg); |
| 4324 | } else if (op->IsShr()) { |
| 4325 | __ sarl(first_reg, second_reg); |
| 4326 | } else { |
| 4327 | __ shrl(first_reg, second_reg); |
| 4328 | } |
| 4329 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4330 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4331 | if (op->IsShl()) { |
| 4332 | __ shll(first_reg, imm); |
| 4333 | } else if (op->IsShr()) { |
| 4334 | __ sarl(first_reg, imm); |
| 4335 | } else { |
| 4336 | __ shrl(first_reg, imm); |
| 4337 | } |
| 4338 | } |
| 4339 | break; |
| 4340 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4341 | case DataType::Type::kInt64: { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4342 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4343 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4344 | if (op->IsShl()) { |
| 4345 | __ shlq(first_reg, second_reg); |
| 4346 | } else if (op->IsShr()) { |
| 4347 | __ sarq(first_reg, second_reg); |
| 4348 | } else { |
| 4349 | __ shrq(first_reg, second_reg); |
| 4350 | } |
| 4351 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4352 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4353 | if (op->IsShl()) { |
| 4354 | __ shlq(first_reg, imm); |
| 4355 | } else if (op->IsShr()) { |
| 4356 | __ sarq(first_reg, imm); |
| 4357 | } else { |
| 4358 | __ shrq(first_reg, imm); |
| 4359 | } |
| 4360 | } |
| 4361 | break; |
| 4362 | } |
| 4363 | default: |
| 4364 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4365 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4366 | } |
| 4367 | } |
| 4368 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4369 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 4370 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4371 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4372 | |
| 4373 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4374 | case DataType::Type::kInt32: |
| 4375 | case DataType::Type::kInt64: { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4376 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4377 | // The shift count needs to be in CL (unless it is a constant). |
| 4378 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 4379 | locations->SetOut(Location::SameAsFirstInput()); |
| 4380 | break; |
| 4381 | } |
| 4382 | default: |
| 4383 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4384 | UNREACHABLE(); |
| 4385 | } |
| 4386 | } |
| 4387 | |
| 4388 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4389 | LocationSummary* locations = ror->GetLocations(); |
| 4390 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4391 | Location second = locations->InAt(1); |
| 4392 | |
| 4393 | switch (ror->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4394 | case DataType::Type::kInt32: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4395 | if (second.IsRegister()) { |
| 4396 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4397 | __ rorl(first_reg, second_reg); |
| 4398 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4399 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4400 | __ rorl(first_reg, imm); |
| 4401 | } |
| 4402 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4403 | case DataType::Type::kInt64: |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4404 | if (second.IsRegister()) { |
| 4405 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4406 | __ rorq(first_reg, second_reg); |
| 4407 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4408 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4409 | __ rorq(first_reg, imm); |
| 4410 | } |
| 4411 | break; |
| 4412 | default: |
| 4413 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4414 | UNREACHABLE(); |
| 4415 | } |
| 4416 | } |
| 4417 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4418 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4419 | HandleShift(shl); |
| 4420 | } |
| 4421 | |
| 4422 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4423 | HandleShift(shl); |
| 4424 | } |
| 4425 | |
| 4426 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4427 | HandleShift(shr); |
| 4428 | } |
| 4429 | |
| 4430 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4431 | HandleShift(shr); |
| 4432 | } |
| 4433 | |
| 4434 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4435 | HandleShift(ushr); |
| 4436 | } |
| 4437 | |
| 4438 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4439 | HandleShift(ushr); |
| 4440 | } |
| 4441 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4442 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4443 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4444 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4445 | InvokeRuntimeCallingConvention calling_convention; |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4446 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4447 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4451 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 4452 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 4453 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4454 | } |
| 4455 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4456 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4457 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4458 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4459 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4460 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4461 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4462 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4463 | } |
| 4464 | |
| 4465 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4466 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 4467 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4468 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4469 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4470 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4471 | } |
| 4472 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4473 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4474 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4475 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4476 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4477 | if (location.IsStackSlot()) { |
| 4478 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4479 | } else if (location.IsDoubleStackSlot()) { |
| 4480 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4481 | } |
| 4482 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4483 | } |
| 4484 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4485 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4486 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4487 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4491 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4492 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4493 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4494 | } |
| 4495 | |
| 4496 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4497 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4498 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4499 | } |
| 4500 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4501 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4502 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4503 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4504 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4505 | locations->SetOut(Location::RequiresRegister()); |
| 4506 | } |
| 4507 | |
| 4508 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4509 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4510 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4511 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4512 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4513 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4514 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4515 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4516 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4517 | instruction->GetIndex(), kX86_64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4518 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4519 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4520 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4521 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4522 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4523 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4524 | } |
| 4525 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4526 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4527 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4528 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4529 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4530 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4531 | } |
| 4532 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4533 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4534 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4535 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4536 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4537 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4538 | switch (not_->GetResultType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4539 | case DataType::Type::kInt32: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4540 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4541 | break; |
| 4542 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4543 | case DataType::Type::kInt64: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4544 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4545 | break; |
| 4546 | |
| 4547 | default: |
| 4548 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4549 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4550 | } |
| 4551 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4552 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4553 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4554 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4555 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4556 | locations->SetOut(Location::SameAsFirstInput()); |
| 4557 | } |
| 4558 | |
| 4559 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4560 | LocationSummary* locations = bool_not->GetLocations(); |
| 4561 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4562 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4563 | Location out = locations->Out(); |
| 4564 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4565 | } |
| 4566 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4567 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4568 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4569 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4570 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4571 | locations->SetInAt(i, Location::Any()); |
| 4572 | } |
| 4573 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4574 | } |
| 4575 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4576 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4577 | LOG(FATAL) << "Unimplemented"; |
| 4578 | } |
| 4579 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4580 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4581 | /* |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4582 | * 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] | 4583 | * 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] | 4584 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4585 | */ |
| 4586 | switch (kind) { |
| 4587 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4588 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4589 | break; |
| 4590 | } |
| 4591 | case MemBarrierKind::kAnyStore: |
| 4592 | case MemBarrierKind::kLoadAny: |
| 4593 | case MemBarrierKind::kStoreStore: { |
| 4594 | // nop |
| 4595 | break; |
| 4596 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4597 | case MemBarrierKind::kNTStoreStore: |
| 4598 | // Non-Temporal Store/Store needs an explicit fence. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4599 | MemoryFence(/* non-temporal= */ true); |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4600 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4601 | } |
| 4602 | } |
| 4603 | |
| 4604 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4605 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4606 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4607 | bool object_field_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4608 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4609 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4610 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4611 | object_field_get_with_read_barrier |
| 4612 | ? LocationSummary::kCallOnSlowPath |
| 4613 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4614 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4615 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4616 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4617 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4618 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4619 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4620 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4621 | // The output overlaps for an object field get when read barriers |
| 4622 | // are enabled: we do not want the move to overwrite the object's |
| 4623 | // location, as we need it to emit the read barrier. |
| 4624 | locations->SetOut( |
| 4625 | Location::RequiresRegister(), |
| 4626 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4627 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4628 | } |
| 4629 | |
| 4630 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4631 | const FieldInfo& field_info) { |
| 4632 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4633 | |
| 4634 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4635 | Location base_loc = locations->InAt(0); |
| 4636 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4637 | Location out = locations->Out(); |
| 4638 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4639 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4640 | DataType::Type load_type = instruction->GetType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4641 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4642 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4643 | switch (load_type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4644 | case DataType::Type::kBool: |
| 4645 | case DataType::Type::kUint8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4646 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4647 | break; |
| 4648 | } |
| 4649 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4650 | case DataType::Type::kInt8: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4651 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4652 | break; |
| 4653 | } |
| 4654 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4655 | case DataType::Type::kUint16: { |
| 4656 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4657 | break; |
| 4658 | } |
| 4659 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4660 | case DataType::Type::kInt16: { |
| 4661 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4662 | break; |
| 4663 | } |
| 4664 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4665 | case DataType::Type::kInt32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4666 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4667 | break; |
| 4668 | } |
| 4669 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4670 | case DataType::Type::kReference: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4671 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4672 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4673 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4674 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4675 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4676 | instruction, out, base, offset, /* needs_null_check= */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4677 | if (is_volatile) { |
| 4678 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4679 | } |
| 4680 | } else { |
| 4681 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4682 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4683 | if (is_volatile) { |
| 4684 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4685 | } |
| 4686 | // If read barriers are enabled, emit read barriers other than |
| 4687 | // Baker's using a slow path (and also unpoison the loaded |
| 4688 | // reference, if heap poisoning is enabled). |
| 4689 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4690 | } |
| 4691 | break; |
| 4692 | } |
| 4693 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4694 | case DataType::Type::kInt64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4695 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4696 | break; |
| 4697 | } |
| 4698 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4699 | case DataType::Type::kFloat32: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4700 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4701 | break; |
| 4702 | } |
| 4703 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4704 | case DataType::Type::kFloat64: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4705 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4706 | break; |
| 4707 | } |
| 4708 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4709 | case DataType::Type::kUint32: |
| 4710 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4711 | case DataType::Type::kVoid: |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4712 | LOG(FATAL) << "Unreachable type " << load_type; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4713 | UNREACHABLE(); |
| 4714 | } |
| 4715 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4716 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4717 | // Potential implicit null checks, in the case of reference |
| 4718 | // fields, are handled in the previous switch statement. |
| 4719 | } else { |
| 4720 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4721 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4722 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4723 | if (is_volatile) { |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4724 | if (load_type == DataType::Type::kReference) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4725 | // Memory barriers, in the case of references, are also handled |
| 4726 | // in the previous switch statement. |
| 4727 | } else { |
| 4728 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4729 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4730 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4731 | } |
| 4732 | |
| 4733 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4734 | const FieldInfo& field_info) { |
| 4735 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4736 | |
| 4737 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4738 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4739 | DataType::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4740 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4741 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4742 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4743 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4744 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4745 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4746 | if (is_volatile) { |
| 4747 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4748 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4749 | } else { |
| 4750 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4751 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4752 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4753 | if (is_volatile) { |
| 4754 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4755 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4756 | } else { |
| 4757 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4758 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4759 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4760 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4761 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4762 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4763 | locations->AddTemp(Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4764 | } else if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4765 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4766 | locations->AddTemp(Location::RequiresRegister()); |
| 4767 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4768 | } |
| 4769 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4770 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4771 | const FieldInfo& field_info, |
| 4772 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4773 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4774 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4775 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4776 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4777 | Location value = locations->InAt(1); |
| 4778 | bool is_volatile = field_info.IsVolatile(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4779 | DataType::Type field_type = field_info.GetFieldType(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4780 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4781 | |
| 4782 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4783 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4784 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4785 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4786 | bool maybe_record_implicit_null_check_done = false; |
| 4787 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4788 | switch (field_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4789 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4790 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4791 | case DataType::Type::kInt8: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4792 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4793 | __ movb(Address(base, offset), |
| 4794 | Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4795 | } else { |
| 4796 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4797 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4798 | break; |
| 4799 | } |
| 4800 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4801 | case DataType::Type::kUint16: |
| 4802 | case DataType::Type::kInt16: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4803 | if (value.IsConstant()) { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4804 | __ movw(Address(base, offset), |
| 4805 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4806 | } else { |
| 4807 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4808 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4809 | break; |
| 4810 | } |
| 4811 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4812 | case DataType::Type::kInt32: |
| 4813 | case DataType::Type::kReference: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4814 | if (value.IsConstant()) { |
| 4815 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4816 | // `field_type == DataType::Type::kReference` implies `v == 0`. |
| 4817 | DCHECK((field_type != DataType::Type::kReference) || (v == 0)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4818 | // Note: if heap poisoning is enabled, no need to poison |
| 4819 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4820 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4821 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4822 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4823 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4824 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4825 | __ PoisonHeapReference(temp); |
| 4826 | __ movl(Address(base, offset), temp); |
| 4827 | } else { |
| 4828 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4829 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4830 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4831 | break; |
| 4832 | } |
| 4833 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4834 | case DataType::Type::kInt64: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4835 | if (value.IsConstant()) { |
| 4836 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4837 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4838 | Address(base, offset + sizeof(int32_t)), |
| 4839 | v, |
| 4840 | instruction); |
| 4841 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4842 | } else { |
| 4843 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4844 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4845 | break; |
| 4846 | } |
| 4847 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4848 | case DataType::Type::kFloat32: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4849 | if (value.IsConstant()) { |
| 4850 | int32_t v = |
| 4851 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4852 | __ movl(Address(base, offset), Immediate(v)); |
| 4853 | } else { |
| 4854 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4855 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4856 | break; |
| 4857 | } |
| 4858 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4859 | case DataType::Type::kFloat64: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4860 | if (value.IsConstant()) { |
| 4861 | int64_t v = |
| 4862 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4863 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4864 | Address(base, offset + sizeof(int32_t)), |
| 4865 | v, |
| 4866 | instruction); |
| 4867 | maybe_record_implicit_null_check_done = true; |
| 4868 | } else { |
| 4869 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4870 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4871 | break; |
| 4872 | } |
| 4873 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4874 | case DataType::Type::kUint32: |
| 4875 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4876 | case DataType::Type::kVoid: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4877 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4878 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4879 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4880 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4881 | if (!maybe_record_implicit_null_check_done) { |
| 4882 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4883 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4884 | |
| 4885 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4886 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4887 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4888 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4889 | } |
| 4890 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4891 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4892 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4893 | } |
| 4894 | } |
| 4895 | |
| 4896 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4897 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4898 | } |
| 4899 | |
| 4900 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4901 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4902 | } |
| 4903 | |
| 4904 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4905 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4909 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4910 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4911 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4912 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4913 | HandleFieldGet(instruction); |
| 4914 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4915 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4916 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4917 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4918 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4919 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4920 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4921 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4922 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4923 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4924 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4925 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4926 | } |
| 4927 | |
Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 4928 | void LocationsBuilderX86_64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 4929 | codegen_->CreateStringBuilderAppendLocations(instruction, Location::RegisterLocation(RAX)); |
| 4930 | } |
| 4931 | |
| 4932 | void InstructionCodeGeneratorX86_64::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 4933 | __ movl(CpuRegister(RDI), Immediate(instruction->GetFormat()->GetValue())); |
| 4934 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 4935 | } |
| 4936 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4937 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4938 | HUnresolvedInstanceFieldGet* instruction) { |
| 4939 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4940 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4941 | instruction, instruction->GetFieldType(), calling_convention); |
| 4942 | } |
| 4943 | |
| 4944 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4945 | HUnresolvedInstanceFieldGet* instruction) { |
| 4946 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4947 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4948 | instruction->GetFieldType(), |
| 4949 | instruction->GetFieldIndex(), |
| 4950 | instruction->GetDexPc(), |
| 4951 | calling_convention); |
| 4952 | } |
| 4953 | |
| 4954 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4955 | HUnresolvedInstanceFieldSet* instruction) { |
| 4956 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4957 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4958 | instruction, instruction->GetFieldType(), calling_convention); |
| 4959 | } |
| 4960 | |
| 4961 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4962 | HUnresolvedInstanceFieldSet* instruction) { |
| 4963 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4964 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4965 | instruction->GetFieldType(), |
| 4966 | instruction->GetFieldIndex(), |
| 4967 | instruction->GetDexPc(), |
| 4968 | calling_convention); |
| 4969 | } |
| 4970 | |
| 4971 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4972 | HUnresolvedStaticFieldGet* instruction) { |
| 4973 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4974 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4975 | instruction, instruction->GetFieldType(), calling_convention); |
| 4976 | } |
| 4977 | |
| 4978 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4979 | HUnresolvedStaticFieldGet* instruction) { |
| 4980 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4981 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4982 | instruction->GetFieldType(), |
| 4983 | instruction->GetFieldIndex(), |
| 4984 | instruction->GetDexPc(), |
| 4985 | calling_convention); |
| 4986 | } |
| 4987 | |
| 4988 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4989 | HUnresolvedStaticFieldSet* instruction) { |
| 4990 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4991 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4992 | instruction, instruction->GetFieldType(), calling_convention); |
| 4993 | } |
| 4994 | |
| 4995 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4996 | HUnresolvedStaticFieldSet* instruction) { |
| 4997 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4998 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4999 | instruction->GetFieldType(), |
| 5000 | instruction->GetFieldIndex(), |
| 5001 | instruction->GetDexPc(), |
| 5002 | calling_convention); |
| 5003 | } |
| 5004 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5005 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5006 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 5007 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 5008 | ? Location::RequiresRegister() |
| 5009 | : Location::Any(); |
| 5010 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5011 | } |
| 5012 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5013 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5014 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5015 | return; |
| 5016 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5017 | LocationSummary* locations = instruction->GetLocations(); |
| 5018 | Location obj = locations->InAt(0); |
| 5019 | |
| 5020 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5021 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5022 | } |
| 5023 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5024 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5025 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5026 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5027 | |
| 5028 | LocationSummary* locations = instruction->GetLocations(); |
| 5029 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5030 | |
| 5031 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5032 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5033 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5034 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5035 | } else { |
| 5036 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5037 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5038 | __ jmp(slow_path->GetEntryLabel()); |
| 5039 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5040 | } |
| 5041 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5042 | } |
| 5043 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5044 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5045 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5046 | } |
| 5047 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5048 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5049 | bool object_array_get_with_read_barrier = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5050 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5051 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5052 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5053 | object_array_get_with_read_barrier |
| 5054 | ? LocationSummary::kCallOnSlowPath |
| 5055 | : LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5056 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5057 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5058 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5059 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5060 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5061 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5062 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5063 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5064 | // The output overlaps for an object array get when read barriers |
| 5065 | // are enabled: we do not want the move to overwrite the array's |
| 5066 | // location, as we need it to emit the read barrier. |
| 5067 | locations->SetOut( |
| 5068 | Location::RequiresRegister(), |
| 5069 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5070 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5071 | } |
| 5072 | |
| 5073 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 5074 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5075 | Location obj_loc = locations->InAt(0); |
| 5076 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5077 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5078 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5079 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5080 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5081 | DataType::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5082 | switch (type) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5083 | case DataType::Type::kBool: |
| 5084 | case DataType::Type::kUint8: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5085 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5086 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5087 | break; |
| 5088 | } |
| 5089 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5090 | case DataType::Type::kInt8: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5091 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5092 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5093 | break; |
| 5094 | } |
| 5095 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5096 | case DataType::Type::kUint16: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5097 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5098 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5099 | // Branch cases into compressed and uncompressed for each index's type. |
| 5100 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5101 | NearLabel done, not_compressed; |
Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5102 | __ testb(Address(obj, count_offset), Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5103 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5104 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5105 | "Expecting 0=compressed, 1=uncompressed"); |
| 5106 | __ j(kNotZero, ¬_compressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5107 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5108 | __ jmp(&done); |
| 5109 | __ Bind(¬_compressed); |
| 5110 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5111 | __ Bind(&done); |
| 5112 | } else { |
| 5113 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5114 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5115 | break; |
| 5116 | } |
| 5117 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5118 | case DataType::Type::kInt16: { |
| 5119 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 5120 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5121 | break; |
| 5122 | } |
| 5123 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5124 | case DataType::Type::kInt32: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5125 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5126 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5127 | break; |
| 5128 | } |
| 5129 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5130 | case DataType::Type::kReference: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5131 | static_assert( |
| 5132 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5133 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5134 | // /* HeapReference<Object> */ out = |
| 5135 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5136 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5137 | // Note that a potential implicit null check is handled in this |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5138 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5139 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5140 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5141 | } else { |
| 5142 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5143 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5144 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5145 | // If read barriers are enabled, emit read barriers other than |
| 5146 | // Baker's using a slow path (and also unpoison the loaded |
| 5147 | // reference, if heap poisoning is enabled). |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5148 | if (index.IsConstant()) { |
| 5149 | uint32_t offset = |
| 5150 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5151 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5152 | } else { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5153 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5154 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5155 | } |
| 5156 | } |
| 5157 | break; |
| 5158 | } |
| 5159 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5160 | case DataType::Type::kInt64: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5161 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5162 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5163 | break; |
| 5164 | } |
| 5165 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5166 | case DataType::Type::kFloat32: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5167 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5168 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5169 | break; |
| 5170 | } |
| 5171 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5172 | case DataType::Type::kFloat64: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5173 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5174 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5175 | break; |
| 5176 | } |
| 5177 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5178 | case DataType::Type::kUint32: |
| 5179 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5180 | case DataType::Type::kVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5181 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5182 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5183 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5184 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5185 | if (type == DataType::Type::kReference) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5186 | // Potential implicit null checks, in the case of reference |
| 5187 | // arrays, are handled in the previous switch statement. |
| 5188 | } else { |
| 5189 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5190 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5191 | } |
| 5192 | |
| 5193 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5194 | DataType::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5195 | |
| 5196 | bool needs_write_barrier = |
| 5197 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5198 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5199 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5200 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5201 | instruction, |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5202 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5203 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5204 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5205 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5206 | if (DataType::IsFloatingPointType(value_type)) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5207 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5208 | } else { |
| 5209 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5210 | } |
| 5211 | |
| 5212 | if (needs_write_barrier) { |
| 5213 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5214 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5215 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5216 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5217 | } |
| 5218 | |
| 5219 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 5220 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5221 | Location array_loc = locations->InAt(0); |
| 5222 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5223 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5224 | Location value = locations->InAt(2); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5225 | DataType::Type value_type = instruction->GetComponentType(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5226 | bool needs_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5227 | bool needs_write_barrier = |
| 5228 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5229 | |
| 5230 | switch (value_type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5231 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5232 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5233 | case DataType::Type::kInt8: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5234 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5235 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5236 | if (value.IsRegister()) { |
| 5237 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5238 | } else { |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5239 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5240 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5241 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5242 | break; |
| 5243 | } |
| 5244 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5245 | case DataType::Type::kUint16: |
| 5246 | case DataType::Type::kInt16: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5247 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5248 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5249 | if (value.IsRegister()) { |
| 5250 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5251 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5252 | DCHECK(value.IsConstant()) << value; |
Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5253 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5254 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5255 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5256 | break; |
| 5257 | } |
| 5258 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5259 | case DataType::Type::kReference: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5260 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5261 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5262 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5263 | if (!value.IsRegister()) { |
| 5264 | // Just setting null. |
| 5265 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5266 | DCHECK(value.IsConstant()) << value; |
| 5267 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5268 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5269 | DCHECK(!needs_write_barrier); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5270 | DCHECK(!needs_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5271 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5272 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5273 | |
| 5274 | DCHECK(needs_write_barrier); |
| 5275 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5276 | Location temp_loc = locations->GetTemp(0); |
| 5277 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5278 | |
| 5279 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 5280 | NearLabel do_store; |
| 5281 | if (can_value_be_null) { |
| 5282 | __ testl(register_value, register_value); |
| 5283 | __ j(kEqual, &do_store); |
| 5284 | } |
| 5285 | |
| 5286 | SlowPathCode* slow_path = nullptr; |
| 5287 | if (needs_type_check) { |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5288 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86_64(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5289 | codegen_->AddSlowPath(slow_path); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5290 | |
| 5291 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5292 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5293 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5294 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5295 | // Note that when Baker read barriers are enabled, the type |
| 5296 | // checks are performed without read barriers. This is fine, |
| 5297 | // even in the case where a class object is in the from-space |
| 5298 | // after the flip, as a comparison involving such a type would |
| 5299 | // not produce a false positive; it may of course produce a |
| 5300 | // false negative, in which case we would take the ArraySet |
| 5301 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5302 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5303 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5304 | __ movl(temp, Address(array, class_offset)); |
| 5305 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5306 | __ MaybeUnpoisonHeapReference(temp); |
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 = temp->component_type_ |
| 5309 | __ movl(temp, Address(temp, component_offset)); |
| 5310 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5311 | // nor the object reference in `register_value->klass`, as |
| 5312 | // we are comparing two poisoned references. |
| 5313 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5314 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5315 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5316 | NearLabel do_put; |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5317 | __ j(kEqual, &do_put); |
| 5318 | // If heap poisoning is enabled, the `temp` reference has |
| 5319 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5320 | __ MaybeUnpoisonHeapReference(temp); |
| 5321 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5322 | // If heap poisoning is enabled, no need to unpoison the |
| 5323 | // heap reference loaded below, as it is only used for a |
| 5324 | // comparison with null. |
| 5325 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5326 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5327 | __ Bind(&do_put); |
| 5328 | } else { |
| 5329 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5330 | } |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5331 | } |
| 5332 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5333 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 5334 | codegen_->MarkGCCard( |
| 5335 | temp, card, array, value.AsRegister<CpuRegister>(), /* value_can_be_null= */ false); |
| 5336 | |
| 5337 | if (can_value_be_null) { |
| 5338 | DCHECK(do_store.IsLinked()); |
| 5339 | __ Bind(&do_store); |
| 5340 | } |
| 5341 | |
| 5342 | Location source = value; |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5343 | if (kPoisonHeapReferences) { |
| 5344 | __ movl(temp, register_value); |
| 5345 | __ PoisonHeapReference(temp); |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5346 | source = temp_loc; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5347 | } |
| 5348 | |
Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 5349 | __ movl(address, source.AsRegister<CpuRegister>()); |
| 5350 | |
| 5351 | if (can_value_be_null || !needs_type_check) { |
| 5352 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5353 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5354 | |
Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 5355 | if (slow_path != nullptr) { |
| 5356 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5357 | } |
| 5358 | |
| 5359 | break; |
| 5360 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5361 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5362 | case DataType::Type::kInt32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5363 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5364 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5365 | if (value.IsRegister()) { |
| 5366 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 5367 | } else { |
| 5368 | DCHECK(value.IsConstant()) << value; |
| 5369 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5370 | __ movl(address, Immediate(v)); |
| 5371 | } |
| 5372 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5373 | break; |
| 5374 | } |
| 5375 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5376 | case DataType::Type::kInt64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5377 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5378 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5379 | if (value.IsRegister()) { |
| 5380 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5381 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5382 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5383 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5384 | Address address_high = |
| 5385 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5386 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5387 | } |
| 5388 | break; |
| 5389 | } |
| 5390 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5391 | case DataType::Type::kFloat32: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5392 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5393 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5394 | if (value.IsFpuRegister()) { |
| 5395 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5396 | } else { |
| 5397 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5398 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5399 | __ movl(address, Immediate(v)); |
| 5400 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5401 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5402 | break; |
| 5403 | } |
| 5404 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5405 | case DataType::Type::kFloat64: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5406 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5407 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5408 | if (value.IsFpuRegister()) { |
| 5409 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5410 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5411 | } else { |
| 5412 | int64_t v = |
| 5413 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5414 | Address address_high = |
| 5415 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5416 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5417 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5418 | break; |
| 5419 | } |
| 5420 | |
Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5421 | case DataType::Type::kUint32: |
| 5422 | case DataType::Type::kUint64: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5423 | case DataType::Type::kVoid: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5424 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5425 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5426 | } |
| 5427 | } |
| 5428 | |
| 5429 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5430 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5431 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5432 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5433 | if (!instruction->IsEmittedAtUseSite()) { |
| 5434 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5435 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5436 | } |
| 5437 | |
| 5438 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5439 | if (instruction->IsEmittedAtUseSite()) { |
| 5440 | return; |
| 5441 | } |
| 5442 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5443 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5444 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5445 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5446 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5447 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5448 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5449 | // Mask out most significant bit in case the array is String's array of char. |
| 5450 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5451 | __ shrl(out, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5452 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5453 | } |
| 5454 | |
| 5455 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5456 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5457 | InvokeRuntimeCallingConvention calling_convention; |
| 5458 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5459 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5460 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5461 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5462 | HInstruction* length = instruction->InputAt(1); |
| 5463 | if (!length->IsEmittedAtUseSite()) { |
| 5464 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5465 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5466 | } |
| 5467 | |
| 5468 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5469 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5470 | Location index_loc = locations->InAt(0); |
| 5471 | Location length_loc = locations->InAt(1); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5472 | SlowPathCode* slow_path = |
| 5473 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5474 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5475 | if (length_loc.IsConstant()) { |
| 5476 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5477 | if (index_loc.IsConstant()) { |
| 5478 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5479 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5480 | if (index < 0 || index >= length) { |
| 5481 | codegen_->AddSlowPath(slow_path); |
| 5482 | __ jmp(slow_path->GetEntryLabel()); |
| 5483 | } else { |
| 5484 | // Some optimization after BCE may have generated this, and we should not |
| 5485 | // generate a bounds check if it is a valid range. |
| 5486 | } |
| 5487 | return; |
| 5488 | } |
| 5489 | |
| 5490 | // We have to reverse the jump condition because the length is the constant. |
| 5491 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5492 | __ cmpl(index_reg, Immediate(length)); |
| 5493 | codegen_->AddSlowPath(slow_path); |
| 5494 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5495 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5496 | HInstruction* array_length = instruction->InputAt(1); |
| 5497 | if (array_length->IsEmittedAtUseSite()) { |
| 5498 | // Address the length field in the array. |
| 5499 | DCHECK(array_length->IsArrayLength()); |
| 5500 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5501 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5502 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5503 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5504 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5505 | // the string compression flag) with the in-memory length and avoid the temporary. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5506 | CpuRegister length_reg = CpuRegister(TMP); |
| 5507 | __ movl(length_reg, array_len); |
| 5508 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5509 | __ shrl(length_reg, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5510 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5511 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5512 | // Checking the bound for general case: |
| 5513 | // Array of char or String's array when the compression feature off. |
| 5514 | if (index_loc.IsConstant()) { |
| 5515 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5516 | __ cmpl(array_len, Immediate(value)); |
| 5517 | } else { |
| 5518 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5519 | } |
| 5520 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5521 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5522 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5523 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5524 | } |
| 5525 | codegen_->AddSlowPath(slow_path); |
| 5526 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5527 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5528 | } |
| 5529 | |
| 5530 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5531 | CpuRegister card, |
| 5532 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5533 | CpuRegister value, |
| 5534 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5535 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5536 | if (value_can_be_null) { |
| 5537 | __ testl(value, value); |
| 5538 | __ j(kEqual, &is_null); |
| 5539 | } |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5540 | // Load the address of the card table into `card`. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5541 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5542 | /* no_rip= */ true)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5543 | // Calculate the offset (in the card table) of the card corresponding to |
| 5544 | // `object`. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5545 | __ movq(temp, object); |
| 5546 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5547 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 5548 | // `object`'s card. |
| 5549 | // |
| 5550 | // Register `card` contains the address of the card table. Note that the card |
| 5551 | // table's base is biased during its creation so that it always starts at an |
| 5552 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 5553 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction |
| 5554 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 5555 | // (located at `card + object >> kCardShift`). |
| 5556 | // |
| 5557 | // This dual use of the value in register `card` (1. to calculate the location |
| 5558 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 5559 | // (no need to explicitly load `kCardDirty` as an immediate value). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5560 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5561 | if (value_can_be_null) { |
| 5562 | __ Bind(&is_null); |
| 5563 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5564 | } |
| 5565 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5566 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5567 | LOG(FATAL) << "Unimplemented"; |
| 5568 | } |
| 5569 | |
| 5570 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5571 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5572 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5573 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5574 | // The back edge will generate the suspend check. |
| 5575 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5576 | } |
| 5577 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5578 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5579 | } |
| 5580 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5581 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5582 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5583 | instruction, LocationSummary::kCallOnSlowPath); |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5584 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5585 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5586 | // registers in full width (since the runtime only saves/restores lower part). |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5587 | locations->SetCustomSlowPathCallerSaves( |
| 5588 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5589 | } |
| 5590 | |
| 5591 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5592 | HBasicBlock* block = instruction->GetBlock(); |
| 5593 | if (block->GetLoopInformation() != nullptr) { |
| 5594 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5595 | // The back edge will generate the suspend check. |
| 5596 | return; |
| 5597 | } |
| 5598 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5599 | // The goto will generate the suspend check. |
| 5600 | return; |
| 5601 | } |
| 5602 | GenerateSuspendCheck(instruction, nullptr); |
| 5603 | } |
| 5604 | |
| 5605 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5606 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5607 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5608 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5609 | if (slow_path == nullptr) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5610 | slow_path = |
| 5611 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86_64(instruction, successor); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5612 | instruction->SetSlowPath(slow_path); |
| 5613 | codegen_->AddSlowPath(slow_path); |
| 5614 | if (successor != nullptr) { |
| 5615 | DCHECK(successor->IsLoopHeader()); |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5616 | } |
| 5617 | } else { |
| 5618 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5619 | } |
| 5620 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5621 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5622 | /* no_rip= */ true), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5623 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5624 | if (successor == nullptr) { |
| 5625 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5626 | __ Bind(slow_path->GetReturnLabel()); |
| 5627 | } else { |
| 5628 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5629 | __ jmp(slow_path->GetEntryLabel()); |
| 5630 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5631 | } |
| 5632 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5633 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5634 | return codegen_->GetAssembler(); |
| 5635 | } |
| 5636 | |
| 5637 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5638 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5639 | Location source = move->GetSource(); |
| 5640 | Location destination = move->GetDestination(); |
| 5641 | |
| 5642 | if (source.IsRegister()) { |
| 5643 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5644 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5645 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5646 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5647 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5648 | } else { |
| 5649 | DCHECK(destination.IsDoubleStackSlot()); |
| 5650 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5651 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5652 | } |
| 5653 | } else if (source.IsStackSlot()) { |
| 5654 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5655 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5656 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5657 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5658 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5659 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5660 | } else { |
| 5661 | DCHECK(destination.IsStackSlot()); |
| 5662 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5663 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5664 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5665 | } else if (source.IsDoubleStackSlot()) { |
| 5666 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5667 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5668 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5669 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5670 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5671 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5672 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5673 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5674 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5675 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5676 | } |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5677 | } else if (source.IsSIMDStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5678 | if (destination.IsFpuRegister()) { |
| 5679 | __ movups(destination.AsFpuRegister<XmmRegister>(), |
| 5680 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5681 | } else { |
| 5682 | DCHECK(destination.IsSIMDStackSlot()); |
| 5683 | size_t high = kX86_64WordSize; |
| 5684 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5685 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5686 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex() + high)); |
| 5687 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex() + high), CpuRegister(TMP)); |
| 5688 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5689 | } else if (source.IsConstant()) { |
| 5690 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5691 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5692 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5693 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5694 | if (value == 0) { |
| 5695 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5696 | } else { |
| 5697 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5698 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5699 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5700 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5701 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5702 | } |
| 5703 | } else if (constant->IsLongConstant()) { |
| 5704 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5705 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5706 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5707 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5708 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5709 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5710 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5711 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5712 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5713 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5714 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5715 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5716 | } else { |
| 5717 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5718 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5719 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5720 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5721 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5722 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5723 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5724 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5725 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5726 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5727 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5728 | } else { |
| 5729 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5730 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5731 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5732 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5733 | } else if (source.IsFpuRegister()) { |
| 5734 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5735 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5736 | } else if (destination.IsStackSlot()) { |
| 5737 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5738 | source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5739 | } else if (destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5740 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5741 | source.AsFpuRegister<XmmRegister>()); |
Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5742 | } else { |
| 5743 | DCHECK(destination.IsSIMDStackSlot()); |
| 5744 | __ movups(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 5745 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5746 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5747 | } |
| 5748 | } |
| 5749 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5750 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5751 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5752 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5753 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5754 | } |
| 5755 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5756 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5757 | __ movq(CpuRegister(TMP), reg1); |
| 5758 | __ movq(reg1, reg2); |
| 5759 | __ movq(reg2, CpuRegister(TMP)); |
| 5760 | } |
| 5761 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5762 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5763 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5764 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5765 | __ movq(reg, CpuRegister(TMP)); |
| 5766 | } |
| 5767 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5768 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5769 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5770 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5771 | __ movd(reg, CpuRegister(TMP)); |
| 5772 | } |
| 5773 | |
| 5774 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5775 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5776 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5777 | __ movd(reg, CpuRegister(TMP)); |
| 5778 | } |
| 5779 | |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5780 | void ParallelMoveResolverX86_64::Exchange128(XmmRegister reg, int mem) { |
| 5781 | size_t extra_slot = 2 * kX86_64WordSize; |
| 5782 | __ subq(CpuRegister(RSP), Immediate(extra_slot)); |
| 5783 | __ movups(Address(CpuRegister(RSP), 0), XmmRegister(reg)); |
| 5784 | ExchangeMemory64(0, mem + extra_slot, 2); |
| 5785 | __ movups(XmmRegister(reg), Address(CpuRegister(RSP), 0)); |
| 5786 | __ addq(CpuRegister(RSP), Immediate(extra_slot)); |
| 5787 | } |
| 5788 | |
| 5789 | void ParallelMoveResolverX86_64::ExchangeMemory32(int mem1, int mem2) { |
| 5790 | ScratchRegisterScope ensure_scratch( |
| 5791 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5792 | |
| 5793 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5794 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5795 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5796 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5797 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5798 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5799 | CpuRegister(ensure_scratch.GetRegister())); |
| 5800 | } |
| 5801 | |
| 5802 | void ParallelMoveResolverX86_64::ExchangeMemory64(int mem1, int mem2, int num_of_qwords) { |
| 5803 | ScratchRegisterScope ensure_scratch( |
| 5804 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5805 | |
| 5806 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5807 | |
| 5808 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 5809 | for (int i = 0; i < num_of_qwords; i++) { |
| 5810 | __ movq(CpuRegister(TMP), |
| 5811 | Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5812 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5813 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5814 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), |
| 5815 | CpuRegister(TMP)); |
| 5816 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5817 | CpuRegister(ensure_scratch.GetRegister())); |
| 5818 | stack_offset += kX86_64WordSize; |
| 5819 | } |
| 5820 | } |
| 5821 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5822 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5823 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5824 | Location source = move->GetSource(); |
| 5825 | Location destination = move->GetDestination(); |
| 5826 | |
| 5827 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5828 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5829 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5830 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5831 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5832 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5833 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5834 | ExchangeMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5835 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5836 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5837 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5838 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5839 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5840 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 1); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5841 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5842 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5843 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5844 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5845 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5846 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5847 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5848 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5849 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5850 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5851 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5852 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5853 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 5854 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 5855 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 5856 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5857 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 5858 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5859 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5860 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5861 | } |
| 5862 | } |
| 5863 | |
| 5864 | |
| 5865 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5866 | __ pushq(CpuRegister(reg)); |
| 5867 | } |
| 5868 | |
| 5869 | |
| 5870 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5871 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5872 | } |
| 5873 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5874 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5875 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 5876 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 5877 | const size_t status_byte_offset = |
| 5878 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 5879 | constexpr uint32_t shifted_visibly_initialized_value = |
| 5880 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << (status_lsb_position % kBitsPerByte); |
Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 5881 | |
Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 5882 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_visibly_initialized_value)); |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 5883 | __ j(kBelow, slow_path->GetEntryLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5884 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5885 | } |
| 5886 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5887 | void InstructionCodeGeneratorX86_64::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 5888 | CpuRegister temp) { |
| 5889 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 5890 | uint32_t mask = check->GetBitstringMask(); |
| 5891 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 5892 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 5893 | |
| 5894 | if (mask_bits == 16u) { |
| 5895 | // Compare the bitstring in memory. |
| 5896 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 5897 | } else { |
| 5898 | // /* uint32_t */ temp = temp->status_ |
| 5899 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 5900 | // Compare the bitstring bits using SUB. |
| 5901 | __ subl(temp, Immediate(path_to_root)); |
| 5902 | // Shift out bits that do not contribute to the comparison. |
| 5903 | __ shll(temp, Immediate(32u - mask_bits)); |
| 5904 | } |
| 5905 | } |
| 5906 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5907 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5908 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5909 | switch (desired_class_load_kind) { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5910 | case HLoadClass::LoadKind::kInvalid: |
| 5911 | LOG(FATAL) << "UNREACHABLE"; |
| 5912 | UNREACHABLE(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5913 | case HLoadClass::LoadKind::kReferrersClass: |
| 5914 | break; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5915 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5916 | case HLoadClass::LoadKind::kBootImageRelRo: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5917 | case HLoadClass::LoadKind::kBssEntry: |
| 5918 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5919 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5920 | case HLoadClass::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5921 | case HLoadClass::LoadKind::kJitTableAddress: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5922 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5923 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5924 | case HLoadClass::LoadKind::kRuntimeCall: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5925 | break; |
| 5926 | } |
| 5927 | return desired_class_load_kind; |
| 5928 | } |
| 5929 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5930 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5931 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5932 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5933 | // Custom calling convention: RAX serves as both input and output. |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5934 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5935 | cls, |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5936 | Location::RegisterLocation(RAX), |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5937 | Location::RegisterLocation(RAX)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5938 | return; |
| 5939 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5940 | DCHECK(!cls->NeedsAccessCheck()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5941 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5942 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5943 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5944 | ? LocationSummary::kCallOnSlowPath |
| 5945 | : LocationSummary::kNoCall; |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5946 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5947 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5948 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5949 | } |
| 5950 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5951 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5952 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5953 | } |
| 5954 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5955 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5956 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5957 | // Rely on the type resolution and/or initialization to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 5958 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5959 | } else { |
| 5960 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5961 | } |
| 5962 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5963 | } |
| 5964 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5965 | Label* CodeGeneratorX86_64::NewJitRootClassPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5966 | dex::TypeIndex type_index, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5967 | Handle<mirror::Class> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5968 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5969 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5970 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5971 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 5972 | return &info->label; |
| 5973 | } |
| 5974 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5975 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5976 | // move. |
| 5977 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5978 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5979 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5980 | codegen_->GenerateLoadClassRuntimeCall(cls); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5981 | return; |
| 5982 | } |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5983 | DCHECK(!cls->NeedsAccessCheck()); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5984 | |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5985 | LocationSummary* locations = cls->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5986 | Location out_loc = locations->Out(); |
| 5987 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5988 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5989 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5990 | ? kWithoutReadBarrier |
| 5991 | : kCompilerReadBarrierOption; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5992 | bool generate_null_check = false; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5993 | switch (load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5994 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5995 | DCHECK(!cls->CanCallRuntime()); |
| 5996 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5997 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5998 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5999 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6000 | cls, |
| 6001 | out_loc, |
| 6002 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6003 | /* fixup_label= */ nullptr, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6004 | read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6005 | break; |
| 6006 | } |
| 6007 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6008 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6009 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6010 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6011 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6012 | codegen_->RecordBootImageTypePatch(cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6013 | break; |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6014 | case HLoadClass::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6015 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6016 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6017 | codegen_->RecordBootImageRelRoPatch(codegen_->GetBootImageOffset(cls)); |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6018 | break; |
| 6019 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6020 | case HLoadClass::LoadKind::kBssEntry: { |
| 6021 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6022 | /* no_rip= */ false); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6023 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 6024 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 6025 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6026 | // No need for memory fence, thanks to the x86-64 memory model. |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6027 | generate_null_check = true; |
| 6028 | break; |
| 6029 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6030 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 6031 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 6032 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 6033 | DCHECK_NE(address, 0u); |
| 6034 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| 6035 | break; |
| 6036 | } |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6037 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 6038 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6039 | /* no_rip= */ true); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6040 | Label* fixup_label = |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6041 | codegen_->NewJitRootClassPatch(cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6042 | // /* GcRoot<mirror::Class> */ out = *address |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6043 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6044 | break; |
| 6045 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6046 | default: |
| 6047 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 6048 | UNREACHABLE(); |
| 6049 | } |
| 6050 | |
| 6051 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6052 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6053 | SlowPathCode* slow_path = |
| 6054 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64(cls, cls); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6055 | codegen_->AddSlowPath(slow_path); |
| 6056 | if (generate_null_check) { |
| 6057 | __ testl(out, out); |
| 6058 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6059 | } |
| 6060 | if (cls->MustGenerateClinitCheck()) { |
| 6061 | GenerateClassInitializationCheck(slow_path, out); |
| 6062 | } else { |
| 6063 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6064 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6065 | } |
| 6066 | } |
| 6067 | |
| 6068 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 6069 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6070 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6071 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6072 | if (check->HasUses()) { |
| 6073 | locations->SetOut(Location::SameAsFirstInput()); |
| 6074 | } |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6075 | // Rely on the type initialization to save everything we need. |
| 6076 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6077 | } |
| 6078 | |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6079 | void LocationsBuilderX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6080 | // Custom calling convention: RAX serves as both input and output. |
| 6081 | Location location = Location::RegisterLocation(RAX); |
| 6082 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 6083 | } |
| 6084 | |
| 6085 | void InstructionCodeGeneratorX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 6086 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 6087 | } |
| 6088 | |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6089 | void LocationsBuilderX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 6090 | // Custom calling convention: RAX serves as both input and output. |
| 6091 | Location location = Location::RegisterLocation(RAX); |
| 6092 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 6093 | } |
| 6094 | |
| 6095 | void InstructionCodeGeneratorX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 6096 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 6097 | } |
| 6098 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6099 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6100 | // We assume the class to not be null. |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6101 | SlowPathCode* slow_path = |
| 6102 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64(check->GetLoadClass(), check); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6103 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6104 | GenerateClassInitializationCheck(slow_path, |
| 6105 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6106 | } |
| 6107 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6108 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 6109 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6110 | switch (desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6111 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6112 | case HLoadString::LoadKind::kBootImageRelRo: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6113 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6114 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6115 | break; |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6116 | case HLoadString::LoadKind::kJitBootImageAddress: |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6117 | case HLoadString::LoadKind::kJitTableAddress: |
| 6118 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6119 | break; |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6120 | case HLoadString::LoadKind::kRuntimeCall: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6121 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6122 | } |
| 6123 | return desired_string_load_kind; |
| 6124 | } |
| 6125 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6126 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6127 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6128 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6129 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6130 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 6131 | } else { |
| 6132 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6133 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 6134 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6135 | // Rely on the pResolveString to save everything. |
Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6136 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6137 | } else { |
| 6138 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6139 | } |
| 6140 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6141 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6142 | } |
| 6143 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6144 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6145 | dex::StringIndex string_index, |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6146 | Handle<mirror::String> handle) { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6147 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6148 | // Add a patch entry and return the label. |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6149 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6150 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6151 | return &info->label; |
| 6152 | } |
| 6153 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6154 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6155 | // move. |
| 6156 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6157 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6158 | Location out_loc = locations->Out(); |
| 6159 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6160 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6161 | switch (load->GetLoadKind()) { |
| 6162 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 6163 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 6164 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6165 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6166 | codegen_->RecordBootImageStringPatch(load); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6167 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6168 | } |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6169 | case HLoadString::LoadKind::kBootImageRelRo: { |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6170 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6171 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip= */ false)); |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6172 | codegen_->RecordBootImageRelRoPatch(codegen_->GetBootImageOffset(load)); |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6173 | return; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6174 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6175 | case HLoadString::LoadKind::kBssEntry: { |
| 6176 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6177 | /* no_rip= */ false); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6178 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 6179 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6180 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 6181 | // No need for memory fence, thanks to the x86-64 memory model. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6182 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86_64(load); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6183 | codegen_->AddSlowPath(slow_path); |
| 6184 | __ testl(out, out); |
| 6185 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6186 | __ Bind(slow_path->GetExitLabel()); |
| 6187 | return; |
| 6188 | } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6189 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 6190 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 6191 | DCHECK_NE(address, 0u); |
| 6192 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| 6193 | return; |
| 6194 | } |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6195 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6196 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6197 | /* no_rip= */ true); |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6198 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 6199 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6200 | // /* GcRoot<mirror::String> */ out = *address |
| 6201 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6202 | return; |
| 6203 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6204 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6205 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6206 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6207 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6208 | // 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] | 6209 | // Custom calling convention: RAX serves as both input and output. |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6210 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex().index_)); |
Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6211 | codegen_->InvokeRuntime(kQuickResolveString, |
| 6212 | load, |
| 6213 | load->GetDexPc()); |
| 6214 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6215 | } |
| 6216 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6217 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6218 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6219 | /* no_rip= */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6220 | } |
| 6221 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6222 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 6223 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6224 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6225 | locations->SetOut(Location::RequiresRegister()); |
| 6226 | } |
| 6227 | |
| 6228 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6229 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 6230 | } |
| 6231 | |
| 6232 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6233 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6234 | } |
| 6235 | |
| 6236 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6237 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6238 | } |
| 6239 | |
| 6240 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6241 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6242 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6243 | InvokeRuntimeCallingConvention calling_convention; |
| 6244 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6245 | } |
| 6246 | |
| 6247 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6248 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6249 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6250 | } |
| 6251 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6252 | // Temp is used for read barrier. |
| 6253 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6254 | if (kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6255 | !kUseBakerReadBarrier && |
| 6256 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6257 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6258 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6259 | return 1; |
| 6260 | } |
| 6261 | return 0; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6262 | } |
| 6263 | |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6264 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 6265 | // interface pointer, the current interface is compared in memory. |
| 6266 | // The other checks have one temp for loading the object's class. |
| 6267 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6268 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6269 | return 2; |
| 6270 | } |
| 6271 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6272 | } |
| 6273 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6274 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6275 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6276 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6277 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6278 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6279 | case TypeCheckKind::kExactCheck: |
| 6280 | case TypeCheckKind::kAbstractClassCheck: |
| 6281 | case TypeCheckKind::kClassHierarchyCheck: |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6282 | case TypeCheckKind::kArrayObjectCheck: { |
| 6283 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6284 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6285 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6286 | break; |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6287 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6288 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6289 | case TypeCheckKind::kUnresolvedCheck: |
| 6290 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6291 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6292 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6293 | case TypeCheckKind::kBitstringCheck: |
| 6294 | break; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6295 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6296 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6297 | LocationSummary* locations = |
| 6298 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6299 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6300 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6301 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6302 | locations->SetInAt(0, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6303 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6304 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6305 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6306 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 6307 | } else { |
| 6308 | locations->SetInAt(1, Location::Any()); |
| 6309 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6310 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 6311 | locations->SetOut(Location::RequiresRegister()); |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6312 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6313 | } |
| 6314 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6315 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6316 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6317 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6318 | Location obj_loc = locations->InAt(0); |
| 6319 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6320 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6321 | Location out_loc = locations->Out(); |
| 6322 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6323 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6324 | DCHECK_LE(num_temps, 1u); |
| 6325 | Location maybe_temp_loc = (num_temps >= 1u) ? locations->GetTemp(0) : Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6326 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6327 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6328 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6329 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6330 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6331 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6332 | |
| 6333 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6334 | // Avoid null check if we know obj is not null. |
| 6335 | if (instruction->MustDoNullCheck()) { |
| 6336 | __ testl(obj, obj); |
| 6337 | __ j(kEqual, &zero); |
| 6338 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6339 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6340 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6341 | case TypeCheckKind::kExactCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6342 | ReadBarrierOption read_barrier_option = |
| 6343 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6344 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6345 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6346 | out_loc, |
| 6347 | obj_loc, |
| 6348 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6349 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6350 | if (cls.IsRegister()) { |
| 6351 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6352 | } else { |
| 6353 | DCHECK(cls.IsStackSlot()) << cls; |
| 6354 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6355 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6356 | if (zero.IsLinked()) { |
| 6357 | // Classes must be equal for the instanceof to succeed. |
| 6358 | __ j(kNotEqual, &zero); |
| 6359 | __ movl(out, Immediate(1)); |
| 6360 | __ jmp(&done); |
| 6361 | } else { |
| 6362 | __ setcc(kEqual, out); |
| 6363 | // setcc only sets the low byte. |
| 6364 | __ andl(out, Immediate(1)); |
| 6365 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6366 | break; |
| 6367 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6368 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6369 | case TypeCheckKind::kAbstractClassCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6370 | ReadBarrierOption read_barrier_option = |
| 6371 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6372 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6373 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6374 | out_loc, |
| 6375 | obj_loc, |
| 6376 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6377 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6378 | // If the class is abstract, we eagerly fetch the super class of the |
| 6379 | // object to avoid doing a comparison we know will fail. |
| 6380 | NearLabel loop, success; |
| 6381 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6382 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6383 | GenerateReferenceLoadOneRegister(instruction, |
| 6384 | out_loc, |
| 6385 | super_offset, |
| 6386 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6387 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6388 | __ testl(out, out); |
| 6389 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6390 | __ j(kEqual, &done); |
| 6391 | if (cls.IsRegister()) { |
| 6392 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6393 | } else { |
| 6394 | DCHECK(cls.IsStackSlot()) << cls; |
| 6395 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6396 | } |
| 6397 | __ j(kNotEqual, &loop); |
| 6398 | __ movl(out, Immediate(1)); |
| 6399 | if (zero.IsLinked()) { |
| 6400 | __ jmp(&done); |
| 6401 | } |
| 6402 | break; |
| 6403 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6404 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6405 | case TypeCheckKind::kClassHierarchyCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6406 | ReadBarrierOption read_barrier_option = |
| 6407 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6408 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6409 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6410 | out_loc, |
| 6411 | obj_loc, |
| 6412 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6413 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6414 | // Walk over the class hierarchy to find a match. |
| 6415 | NearLabel loop, success; |
| 6416 | __ Bind(&loop); |
| 6417 | if (cls.IsRegister()) { |
| 6418 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6419 | } else { |
| 6420 | DCHECK(cls.IsStackSlot()) << cls; |
| 6421 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6422 | } |
| 6423 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6424 | // /* HeapReference<Class> */ out = out->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6425 | GenerateReferenceLoadOneRegister(instruction, |
| 6426 | out_loc, |
| 6427 | super_offset, |
| 6428 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6429 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6430 | __ testl(out, out); |
| 6431 | __ j(kNotEqual, &loop); |
| 6432 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6433 | __ jmp(&done); |
| 6434 | __ Bind(&success); |
| 6435 | __ movl(out, Immediate(1)); |
| 6436 | if (zero.IsLinked()) { |
| 6437 | __ jmp(&done); |
| 6438 | } |
| 6439 | break; |
| 6440 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6441 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6442 | case TypeCheckKind::kArrayObjectCheck: { |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6443 | ReadBarrierOption read_barrier_option = |
| 6444 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6445 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6446 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6447 | out_loc, |
| 6448 | obj_loc, |
| 6449 | class_offset, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6450 | read_barrier_option); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6451 | // Do an exact check. |
| 6452 | NearLabel exact_check; |
| 6453 | if (cls.IsRegister()) { |
| 6454 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6455 | } else { |
| 6456 | DCHECK(cls.IsStackSlot()) << cls; |
| 6457 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6458 | } |
| 6459 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6460 | // 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] | 6461 | // /* HeapReference<Class> */ out = out->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6462 | GenerateReferenceLoadOneRegister(instruction, |
| 6463 | out_loc, |
| 6464 | component_offset, |
| 6465 | maybe_temp_loc, |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6466 | read_barrier_option); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6467 | __ testl(out, out); |
| 6468 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6469 | __ j(kEqual, &done); |
| 6470 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6471 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6472 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6473 | __ movl(out, Immediate(1)); |
| 6474 | __ jmp(&done); |
| 6475 | break; |
| 6476 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6477 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6478 | case TypeCheckKind::kArrayCheck: { |
Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6479 | // No read barrier since the slow path will retry upon failure. |
| 6480 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6481 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6482 | out_loc, |
| 6483 | obj_loc, |
| 6484 | class_offset, |
| 6485 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6486 | if (cls.IsRegister()) { |
| 6487 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6488 | } else { |
| 6489 | DCHECK(cls.IsStackSlot()) << cls; |
| 6490 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6491 | } |
| 6492 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6493 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6494 | instruction, /* is_fatal= */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6495 | codegen_->AddSlowPath(slow_path); |
| 6496 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6497 | __ movl(out, Immediate(1)); |
| 6498 | if (zero.IsLinked()) { |
| 6499 | __ jmp(&done); |
| 6500 | } |
| 6501 | break; |
| 6502 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6503 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6504 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6505 | case TypeCheckKind::kInterfaceCheck: { |
| 6506 | // 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] | 6507 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6508 | // cases. |
| 6509 | // |
| 6510 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6511 | // entry point without resorting to a type checking slow path |
| 6512 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6513 | // require to assign fixed registers for the inputs of this |
| 6514 | // HInstanceOf instruction (following the runtime calling |
| 6515 | // convention), which might be cluttered by the potential first |
| 6516 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6517 | // |
| 6518 | // TODO: Introduce a new runtime entry point taking the object |
| 6519 | // to test (instead of its class) as argument, and let it deal |
| 6520 | // with the read barrier issues. This will let us refactor this |
| 6521 | // case of the `switch` code as it was previously (with a direct |
| 6522 | // call to the runtime not using a type checking slow path). |
| 6523 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6524 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6525 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6526 | instruction, /* is_fatal= */ false); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6527 | codegen_->AddSlowPath(slow_path); |
| 6528 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6529 | if (zero.IsLinked()) { |
| 6530 | __ jmp(&done); |
| 6531 | } |
| 6532 | break; |
| 6533 | } |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6534 | |
| 6535 | case TypeCheckKind::kBitstringCheck: { |
| 6536 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6537 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6538 | out_loc, |
| 6539 | obj_loc, |
| 6540 | class_offset, |
| 6541 | kWithoutReadBarrier); |
| 6542 | |
| 6543 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 6544 | if (zero.IsLinked()) { |
| 6545 | __ j(kNotEqual, &zero); |
| 6546 | __ movl(out, Immediate(1)); |
| 6547 | __ jmp(&done); |
| 6548 | } else { |
| 6549 | __ setcc(kEqual, out); |
| 6550 | // setcc only sets the low byte. |
| 6551 | __ andl(out, Immediate(1)); |
| 6552 | } |
| 6553 | break; |
| 6554 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6555 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6556 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6557 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6558 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6559 | __ xorl(out, out); |
| 6560 | } |
| 6561 | |
| 6562 | if (done.IsLinked()) { |
| 6563 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6564 | } |
| 6565 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6566 | if (slow_path != nullptr) { |
| 6567 | __ Bind(slow_path->GetExitLabel()); |
| 6568 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6569 | } |
| 6570 | |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6571 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6572 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6573 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6574 | LocationSummary* locations = |
| 6575 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6576 | locations->SetInAt(0, Location::RequiresRegister()); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6577 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6578 | // Require a register for the interface check since there is a loop that compares the class to |
| 6579 | // a memory address. |
| 6580 | locations->SetInAt(1, Location::RequiresRegister()); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6581 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6582 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6583 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6584 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6585 | } else { |
| 6586 | locations->SetInAt(1, Location::Any()); |
| 6587 | } |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6588 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathX86. |
| 6589 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6590 | } |
| 6591 | |
| 6592 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6593 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6594 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6595 | Location obj_loc = locations->InAt(0); |
| 6596 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6597 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6598 | Location temp_loc = locations->GetTemp(0); |
| 6599 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6600 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6601 | DCHECK_GE(num_temps, 1u); |
| 6602 | DCHECK_LE(num_temps, 2u); |
| 6603 | Location maybe_temp2_loc = (num_temps >= 2u) ? locations->GetTemp(1) : Location::NoLocation(); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6604 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6605 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6606 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6607 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6608 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6609 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6610 | const uint32_t object_array_data_offset = |
| 6611 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6612 | |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6613 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6614 | SlowPathCode* type_check_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6615 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6616 | instruction, is_type_check_slow_path_fatal); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6617 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6618 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6619 | |
| 6620 | NearLabel done; |
| 6621 | // Avoid null check if we know obj is not null. |
| 6622 | if (instruction->MustDoNullCheck()) { |
| 6623 | __ testl(obj, obj); |
| 6624 | __ j(kEqual, &done); |
| 6625 | } |
| 6626 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6627 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6628 | case TypeCheckKind::kExactCheck: |
| 6629 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6630 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6631 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6632 | temp_loc, |
| 6633 | obj_loc, |
| 6634 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6635 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6636 | if (cls.IsRegister()) { |
| 6637 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6638 | } else { |
| 6639 | DCHECK(cls.IsStackSlot()) << cls; |
| 6640 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6641 | } |
| 6642 | // Jump to slow path for throwing the exception or doing a |
| 6643 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6644 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6645 | break; |
| 6646 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6647 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6648 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6649 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6650 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6651 | temp_loc, |
| 6652 | obj_loc, |
| 6653 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6654 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6655 | // If the class is abstract, we eagerly fetch the super class of the |
| 6656 | // object to avoid doing a comparison we know will fail. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6657 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6658 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6659 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6660 | GenerateReferenceLoadOneRegister(instruction, |
| 6661 | temp_loc, |
| 6662 | super_offset, |
| 6663 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6664 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6665 | |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6666 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6667 | // exception. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6668 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6669 | // Otherwise, compare the classes. |
| 6670 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6671 | if (cls.IsRegister()) { |
| 6672 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6673 | } else { |
| 6674 | DCHECK(cls.IsStackSlot()) << cls; |
| 6675 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6676 | } |
| 6677 | __ j(kNotEqual, &loop); |
| 6678 | break; |
| 6679 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6680 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6681 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6682 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6683 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6684 | temp_loc, |
| 6685 | obj_loc, |
| 6686 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6687 | kWithoutReadBarrier); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6688 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6689 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6690 | __ Bind(&loop); |
| 6691 | if (cls.IsRegister()) { |
| 6692 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6693 | } else { |
| 6694 | DCHECK(cls.IsStackSlot()) << cls; |
| 6695 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6696 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6697 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6698 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6699 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6700 | GenerateReferenceLoadOneRegister(instruction, |
| 6701 | temp_loc, |
| 6702 | super_offset, |
| 6703 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6704 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6705 | |
| 6706 | // If the class reference currently in `temp` is not null, jump |
| 6707 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6708 | __ testl(temp, temp); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6709 | __ j(kNotZero, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6710 | // Otherwise, jump to the slow path to throw the exception. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6711 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6712 | break; |
| 6713 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6714 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6715 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6716 | // /* HeapReference<Class> */ temp = obj->klass_ |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6717 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6718 | temp_loc, |
| 6719 | obj_loc, |
| 6720 | class_offset, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6721 | kWithoutReadBarrier); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6722 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6723 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6724 | if (cls.IsRegister()) { |
| 6725 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6726 | } else { |
| 6727 | DCHECK(cls.IsStackSlot()) << cls; |
| 6728 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6729 | } |
| 6730 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6731 | |
| 6732 | // 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] | 6733 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6734 | GenerateReferenceLoadOneRegister(instruction, |
| 6735 | temp_loc, |
| 6736 | component_offset, |
| 6737 | maybe_temp2_loc, |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6738 | kWithoutReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6739 | |
| 6740 | // If the component type is not null (i.e. the object is indeed |
| 6741 | // an array), jump to label `check_non_primitive_component_type` |
| 6742 | // to further check that this component type is not a primitive |
| 6743 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6744 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6745 | // Otherwise, jump to the slow path to throw the exception. |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6746 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6747 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6748 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6749 | break; |
| 6750 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6751 | |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6752 | case TypeCheckKind::kUnresolvedCheck: { |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6753 | // 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] | 6754 | // |
| 6755 | // We cannot directly call the CheckCast runtime entry point |
| 6756 | // without resorting to a type checking slow path here (i.e. by |
| 6757 | // calling InvokeRuntime directly), as it would require to |
| 6758 | // assign fixed registers for the inputs of this HInstanceOf |
| 6759 | // instruction (following the runtime calling convention), which |
| 6760 | // might be cluttered by the potential first read barrier |
| 6761 | // emission at the beginning of this method. |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6762 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6763 | break; |
| 6764 | } |
| 6765 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6766 | case TypeCheckKind::kInterfaceCheck: { |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6767 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 6768 | // We can not get false positives by doing this. |
| 6769 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6770 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6771 | temp_loc, |
| 6772 | obj_loc, |
| 6773 | class_offset, |
| 6774 | kWithoutReadBarrier); |
Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6775 | |
Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6776 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6777 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6778 | temp_loc, |
| 6779 | temp_loc, |
| 6780 | iftable_offset, |
| 6781 | kWithoutReadBarrier); |
| 6782 | // Iftable is never null. |
| 6783 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
| 6784 | // Maybe poison the `cls` for direct comparison with memory. |
| 6785 | __ MaybePoisonHeapReference(cls.AsRegister<CpuRegister>()); |
| 6786 | // Loop through the iftable and check if any class matches. |
| 6787 | NearLabel start_loop; |
| 6788 | __ Bind(&start_loop); |
| 6789 | // Need to subtract first to handle the empty array case. |
| 6790 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| 6791 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6792 | // Go to next interface if the classes do not match. |
| 6793 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 6794 | CodeGeneratorX86_64::ArrayAddress(temp, |
| 6795 | maybe_temp2_loc, |
| 6796 | TIMES_4, |
| 6797 | object_array_data_offset)); |
| 6798 | __ j(kNotEqual, &start_loop); // Return if same class. |
| 6799 | // If `cls` was poisoned above, unpoison it. |
| 6800 | __ MaybeUnpoisonHeapReference(cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6801 | break; |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6802 | } |
| 6803 | |
| 6804 | case TypeCheckKind::kBitstringCheck: { |
| 6805 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6806 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6807 | temp_loc, |
| 6808 | obj_loc, |
| 6809 | class_offset, |
| 6810 | kWithoutReadBarrier); |
| 6811 | |
| 6812 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 6813 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 6814 | break; |
| 6815 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6816 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6817 | |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6818 | if (done.IsLinked()) { |
| 6819 | __ Bind(&done); |
| 6820 | } |
| 6821 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6822 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6823 | } |
| 6824 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6825 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6826 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6827 | instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6828 | InvokeRuntimeCallingConvention calling_convention; |
| 6829 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6830 | } |
| 6831 | |
| 6832 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6833 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6834 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6835 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6836 | if (instruction->IsEnter()) { |
| 6837 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6838 | } else { |
| 6839 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6840 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6841 | } |
| 6842 | |
Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 6843 | void LocationsBuilderX86_64::VisitX86AndNot(HX86AndNot* instruction) { |
| 6844 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 6845 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 6846 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 6847 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6848 | // There is no immediate variant of negated bitwise and in X86. |
| 6849 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6850 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6851 | } |
| 6852 | |
| 6853 | void LocationsBuilderX86_64::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 6854 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); |
| 6855 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); |
| 6856 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| 6857 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6858 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6859 | } |
| 6860 | |
| 6861 | void InstructionCodeGeneratorX86_64::VisitX86AndNot(HX86AndNot* instruction) { |
| 6862 | LocationSummary* locations = instruction->GetLocations(); |
| 6863 | Location first = locations->InAt(0); |
| 6864 | Location second = locations->InAt(1); |
| 6865 | Location dest = locations->Out(); |
| 6866 | __ andn(dest.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 6867 | } |
| 6868 | |
| 6869 | void InstructionCodeGeneratorX86_64::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { |
| 6870 | LocationSummary* locations = instruction->GetLocations(); |
| 6871 | Location src = locations->InAt(0); |
| 6872 | Location dest = locations->Out(); |
| 6873 | switch (instruction->GetOpKind()) { |
| 6874 | case HInstruction::kAnd: |
| 6875 | __ blsr(dest.AsRegister<CpuRegister>(), src.AsRegister<CpuRegister>()); |
| 6876 | break; |
| 6877 | case HInstruction::kXor: |
| 6878 | __ blsmsk(dest.AsRegister<CpuRegister>(), src.AsRegister<CpuRegister>()); |
| 6879 | break; |
| 6880 | default: |
| 6881 | LOG(FATAL) << "Unreachable"; |
| 6882 | } |
| 6883 | } |
| 6884 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6885 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6886 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6887 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6888 | |
| 6889 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6890 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6891 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6892 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 6893 | || instruction->GetResultType() == DataType::Type::kInt64); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6894 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6895 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6896 | locations->SetOut(Location::SameAsFirstInput()); |
| 6897 | } |
| 6898 | |
| 6899 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6900 | HandleBitwiseOperation(instruction); |
| 6901 | } |
| 6902 | |
| 6903 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6904 | HandleBitwiseOperation(instruction); |
| 6905 | } |
| 6906 | |
| 6907 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6908 | HandleBitwiseOperation(instruction); |
| 6909 | } |
| 6910 | |
| 6911 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6912 | LocationSummary* locations = instruction->GetLocations(); |
| 6913 | Location first = locations->InAt(0); |
| 6914 | Location second = locations->InAt(1); |
| 6915 | DCHECK(first.Equals(locations->Out())); |
| 6916 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6917 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6918 | if (second.IsRegister()) { |
| 6919 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6920 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6921 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6922 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6923 | } else { |
| 6924 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6925 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6926 | } |
| 6927 | } else if (second.IsConstant()) { |
| 6928 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6929 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6930 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6931 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6932 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6933 | } else { |
| 6934 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6935 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6936 | } |
| 6937 | } else { |
| 6938 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6939 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6940 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6941 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6942 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6943 | } else { |
| 6944 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6945 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6946 | } |
| 6947 | } |
| 6948 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6949 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6950 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6951 | bool second_is_constant = false; |
| 6952 | int64_t value = 0; |
| 6953 | if (second.IsConstant()) { |
| 6954 | second_is_constant = true; |
| 6955 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6956 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6957 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6958 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6959 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6960 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6961 | if (is_int32_value) { |
| 6962 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6963 | } else { |
| 6964 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6965 | } |
| 6966 | } else if (second.IsDoubleStackSlot()) { |
| 6967 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6968 | } else { |
| 6969 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6970 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6971 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6972 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6973 | if (is_int32_value) { |
| 6974 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6975 | } else { |
| 6976 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6977 | } |
| 6978 | } else if (second.IsDoubleStackSlot()) { |
| 6979 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6980 | } else { |
| 6981 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6982 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6983 | } else { |
| 6984 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6985 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6986 | if (is_int32_value) { |
| 6987 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6988 | } else { |
| 6989 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6990 | } |
| 6991 | } else if (second.IsDoubleStackSlot()) { |
| 6992 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6993 | } else { |
| 6994 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6995 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6996 | } |
| 6997 | } |
| 6998 | } |
| 6999 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7000 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister( |
| 7001 | HInstruction* instruction, |
| 7002 | Location out, |
| 7003 | uint32_t offset, |
| 7004 | Location maybe_temp, |
| 7005 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7006 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7007 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7008 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7009 | if (kUseBakerReadBarrier) { |
| 7010 | // Load with fast path based Baker's read barrier. |
| 7011 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7012 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7013 | instruction, out, out_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7014 | } else { |
| 7015 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7016 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7017 | // in the following move operation, as we will need it for the |
| 7018 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7019 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7020 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7021 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7022 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7023 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7024 | } |
| 7025 | } else { |
| 7026 | // Plain load with no read barrier. |
| 7027 | // /* HeapReference<Object> */ out = *(out + offset) |
| 7028 | __ movl(out_reg, Address(out_reg, offset)); |
| 7029 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7030 | } |
| 7031 | } |
| 7032 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7033 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters( |
| 7034 | HInstruction* instruction, |
| 7035 | Location out, |
| 7036 | Location obj, |
| 7037 | uint32_t offset, |
| 7038 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7039 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 7040 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7041 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7042 | CHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7043 | if (kUseBakerReadBarrier) { |
| 7044 | // Load with fast path based Baker's read barrier. |
| 7045 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7046 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7047 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7048 | } else { |
| 7049 | // Load with slow path based read barrier. |
| 7050 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7051 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7052 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 7053 | } |
| 7054 | } else { |
| 7055 | // Plain load with no read barrier. |
| 7056 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 7057 | __ movl(out_reg, Address(obj_reg, offset)); |
| 7058 | __ MaybeUnpoisonHeapReference(out_reg); |
| 7059 | } |
| 7060 | } |
| 7061 | |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7062 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad( |
| 7063 | HInstruction* instruction, |
| 7064 | Location root, |
| 7065 | const Address& address, |
| 7066 | Label* fixup_label, |
| 7067 | ReadBarrierOption read_barrier_option) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7068 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7069 | if (read_barrier_option == kWithReadBarrier) { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7070 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7071 | if (kUseBakerReadBarrier) { |
| 7072 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 7073 | // Baker's read barrier are used: |
| 7074 | // |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7075 | // root = obj.field; |
| 7076 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 7077 | // if (temp != null) { |
| 7078 | // root = temp(root) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7079 | // } |
| 7080 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7081 | // /* GcRoot<mirror::Object> */ root = *address |
| 7082 | __ movl(root_reg, address); |
| 7083 | if (fixup_label != nullptr) { |
| 7084 | __ Bind(fixup_label); |
| 7085 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7086 | static_assert( |
| 7087 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 7088 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 7089 | "have different sizes."); |
| 7090 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 7091 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 7092 | "have different sizes."); |
| 7093 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7094 | // Slow path marking the GC root `root`. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7095 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7096 | instruction, root, /* unpoison_ref_before_marking= */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7097 | codegen_->AddSlowPath(slow_path); |
| 7098 | |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7099 | // Test the `Thread::Current()->pReadBarrierMarkReg ## root.reg()` entrypoint. |
| 7100 | const int32_t entry_point_offset = |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7101 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(root.reg()); |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7102 | __ gs()->cmpl(Address::Absolute(entry_point_offset, /* no_rip= */ true), Immediate(0)); |
Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7103 | // The entrypoint is null when the GC is not marking. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7104 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 7105 | __ Bind(slow_path->GetExitLabel()); |
| 7106 | } else { |
| 7107 | // GC root loaded through a slow path for read barriers other |
| 7108 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7109 | // /* GcRoot<mirror::Object>* */ root = address |
| 7110 | __ leaq(root_reg, address); |
| 7111 | if (fixup_label != nullptr) { |
| 7112 | __ Bind(fixup_label); |
| 7113 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7114 | // /* mirror::Object* */ root = root->Read() |
| 7115 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 7116 | } |
| 7117 | } else { |
| 7118 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7119 | // /* GcRoot<mirror::Object> */ root = *address |
| 7120 | __ movl(root_reg, address); |
| 7121 | if (fixup_label != nullptr) { |
| 7122 | __ Bind(fixup_label); |
| 7123 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7124 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7125 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7126 | } |
| 7127 | } |
| 7128 | |
| 7129 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7130 | Location ref, |
| 7131 | CpuRegister obj, |
| 7132 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7133 | bool needs_null_check) { |
| 7134 | DCHECK(kEmitCompilerReadBarrier); |
| 7135 | DCHECK(kUseBakerReadBarrier); |
| 7136 | |
| 7137 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7138 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7139 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7140 | } |
| 7141 | |
| 7142 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7143 | Location ref, |
| 7144 | CpuRegister obj, |
| 7145 | uint32_t data_offset, |
| 7146 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7147 | bool needs_null_check) { |
| 7148 | DCHECK(kEmitCompilerReadBarrier); |
| 7149 | DCHECK(kUseBakerReadBarrier); |
| 7150 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7151 | static_assert( |
| 7152 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7153 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7154 | // /* HeapReference<Object> */ ref = |
| 7155 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7156 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7157 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7158 | } |
| 7159 | |
| 7160 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7161 | Location ref, |
| 7162 | CpuRegister obj, |
| 7163 | const Address& src, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7164 | bool needs_null_check, |
| 7165 | bool always_update_field, |
| 7166 | CpuRegister* temp1, |
| 7167 | CpuRegister* temp2) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7168 | DCHECK(kEmitCompilerReadBarrier); |
| 7169 | DCHECK(kUseBakerReadBarrier); |
| 7170 | |
| 7171 | // In slow path based read barriers, the read barrier call is |
| 7172 | // inserted after the original load. However, in fast path based |
| 7173 | // Baker's read barriers, we need to perform the load of |
| 7174 | // mirror::Object::monitor_ *before* the original reference load. |
| 7175 | // This load-load ordering is required by the read barrier. |
| 7176 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7177 | // |
| 7178 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7179 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7180 | // HeapReference<Object> ref = *src; // Original reference load. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7181 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7182 | // if (is_gray) { |
| 7183 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7184 | // } |
| 7185 | // |
| 7186 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7187 | // slightly more complex as: |
| 7188 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7189 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7190 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 7191 | // 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] | 7192 | // - it performs additional checks that we do not do here for |
| 7193 | // performance reasons. |
| 7194 | |
| 7195 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7196 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7197 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7198 | // 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] | 7199 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7200 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7201 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7202 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7203 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7204 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7205 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7206 | // ref = ReadBarrier::Mark(ref); |
| 7207 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7208 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7209 | if (needs_null_check) { |
| 7210 | MaybeRecordImplicitNullCheck(instruction); |
| 7211 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7212 | |
| 7213 | // Load fence to prevent load-load reordering. |
| 7214 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 7215 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7216 | |
| 7217 | // The actual reference load. |
| 7218 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7219 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7220 | |
| 7221 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7222 | // Slow path marking the object `ref` when it is gray. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7223 | SlowPathCode* slow_path; |
| 7224 | if (always_update_field) { |
| 7225 | DCHECK(temp1 != nullptr); |
| 7226 | DCHECK(temp2 != nullptr); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7227 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7228 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp1, *temp2); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7229 | } else { |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7230 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7231 | instruction, ref, /* unpoison_ref_before_marking= */ true); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7232 | } |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7233 | AddSlowPath(slow_path); |
| 7234 | |
| 7235 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7236 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7237 | |
| 7238 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7239 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7240 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7241 | __ Bind(slow_path->GetExitLabel()); |
| 7242 | } |
| 7243 | |
| 7244 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7245 | Location out, |
| 7246 | Location ref, |
| 7247 | Location obj, |
| 7248 | uint32_t offset, |
| 7249 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7250 | DCHECK(kEmitCompilerReadBarrier); |
| 7251 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7252 | // Insert a slow path based read barrier *after* the reference load. |
| 7253 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7254 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7255 | // reference will be carried out by the runtime within the slow |
| 7256 | // path. |
| 7257 | // |
| 7258 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7259 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7260 | // not used by the artReadBarrierSlow entry point. |
| 7261 | // |
| 7262 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7263 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7264 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 7265 | AddSlowPath(slow_path); |
| 7266 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7267 | __ jmp(slow_path->GetEntryLabel()); |
| 7268 | __ Bind(slow_path->GetExitLabel()); |
| 7269 | } |
| 7270 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7271 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7272 | Location out, |
| 7273 | Location ref, |
| 7274 | Location obj, |
| 7275 | uint32_t offset, |
| 7276 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7277 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7278 | // Baker's read barriers shall be handled by the fast path |
| 7279 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 7280 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7281 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7282 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7283 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7284 | } else if (kPoisonHeapReferences) { |
| 7285 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 7286 | } |
| 7287 | } |
| 7288 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7289 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7290 | Location out, |
| 7291 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7292 | DCHECK(kEmitCompilerReadBarrier); |
| 7293 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7294 | // Insert a slow path based read barrier *after* the GC root load. |
| 7295 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7296 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7297 | // not need to do anything special for this here. |
| 7298 | SlowPathCode* slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7299 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7300 | AddSlowPath(slow_path); |
| 7301 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7302 | __ jmp(slow_path->GetEntryLabel()); |
| 7303 | __ Bind(slow_path->GetExitLabel()); |
| 7304 | } |
| 7305 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7306 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7307 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7308 | LOG(FATAL) << "Unreachable"; |
| 7309 | } |
| 7310 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7311 | void InstructionCodeGeneratorX86_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 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7316 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7317 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7318 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7319 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7320 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7321 | locations->AddTemp(Location::RequiresRegister()); |
| 7322 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7323 | } |
| 7324 | |
| 7325 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7326 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7327 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7328 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7329 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 7330 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 7331 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7332 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7333 | |
| 7334 | // Should we generate smaller inline compare/jumps? |
| 7335 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7336 | // Figure out the correct compare values and jump conditions. |
| 7337 | // Handle the first compare/branch as a special case because it might |
| 7338 | // jump to the default case. |
| 7339 | DCHECK_GT(num_entries, 2u); |
| 7340 | Condition first_condition; |
| 7341 | uint32_t index; |
| 7342 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7343 | if (lower_bound != 0) { |
| 7344 | first_condition = kLess; |
| 7345 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 7346 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7347 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 7348 | |
| 7349 | index = 1; |
| 7350 | } else { |
| 7351 | // Handle all the compare/jumps below. |
| 7352 | first_condition = kBelow; |
| 7353 | index = 0; |
| 7354 | } |
| 7355 | |
| 7356 | // Handle the rest of the compare/jumps. |
| 7357 | for (; index + 1 < num_entries; index += 2) { |
| 7358 | int32_t compare_to_value = lower_bound + index + 1; |
| 7359 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 7360 | // Jump to successors[index] if value < case_value[index]. |
| 7361 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7362 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7363 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7364 | } |
| 7365 | |
| 7366 | if (index != num_entries) { |
| 7367 | // There are an odd number of entries. Handle the last one. |
| 7368 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 7369 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7370 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 7371 | } |
| 7372 | |
| 7373 | // And the default for any other value. |
| 7374 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7375 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 7376 | } |
| 7377 | return; |
| 7378 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7379 | |
| 7380 | // Remove the bias, if needed. |
| 7381 | Register value_reg_out = value_reg_in.AsRegister(); |
| 7382 | if (lower_bound != 0) { |
| 7383 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 7384 | value_reg_out = temp_reg.AsRegister(); |
| 7385 | } |
| 7386 | CpuRegister value_reg(value_reg_out); |
| 7387 | |
| 7388 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7389 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7390 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7391 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7392 | // We are in the range of the table. |
| 7393 | // Load the address of the jump table in the constant area. |
| 7394 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7395 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7396 | // Load the (signed) offset from the jump table. |
| 7397 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 7398 | |
| 7399 | // Add the offset to the address of the table base. |
| 7400 | __ addq(temp_reg, base_reg); |
| 7401 | |
| 7402 | // And jump. |
| 7403 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7404 | } |
| 7405 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7406 | void LocationsBuilderX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7407 | ATTRIBUTE_UNUSED) { |
| 7408 | LOG(FATAL) << "Unreachable"; |
| 7409 | } |
| 7410 | |
| 7411 | void InstructionCodeGeneratorX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7412 | ATTRIBUTE_UNUSED) { |
| 7413 | LOG(FATAL) << "Unreachable"; |
| 7414 | } |
| 7415 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7416 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 7417 | if (value == 0) { |
| 7418 | __ xorl(dest, dest); |
| 7419 | } else { |
| 7420 | __ movl(dest, Immediate(value)); |
| 7421 | } |
| 7422 | } |
| 7423 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7424 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 7425 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7426 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7427 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 7428 | } else if (IsUint<32>(value)) { |
| 7429 | // 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] | 7430 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 7431 | } else { |
| 7432 | __ movq(dest, Immediate(value)); |
| 7433 | } |
| 7434 | } |
| 7435 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 7436 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 7437 | if (value == 0) { |
| 7438 | __ xorps(dest, dest); |
| 7439 | } else { |
| 7440 | __ movss(dest, LiteralInt32Address(value)); |
| 7441 | } |
| 7442 | } |
| 7443 | |
| 7444 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 7445 | if (value == 0) { |
| 7446 | __ xorpd(dest, dest); |
| 7447 | } else { |
| 7448 | __ movsd(dest, LiteralInt64Address(value)); |
| 7449 | } |
| 7450 | } |
| 7451 | |
| 7452 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 7453 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 7454 | } |
| 7455 | |
| 7456 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 7457 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 7458 | } |
| 7459 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7460 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 7461 | if (value == 0) { |
| 7462 | __ testl(dest, dest); |
| 7463 | } else { |
| 7464 | __ cmpl(dest, Immediate(value)); |
| 7465 | } |
| 7466 | } |
| 7467 | |
| 7468 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 7469 | if (IsInt<32>(value)) { |
| 7470 | if (value == 0) { |
| 7471 | __ testq(dest, dest); |
| 7472 | } else { |
| 7473 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 7474 | } |
| 7475 | } else { |
| 7476 | // Value won't fit in an int. |
| 7477 | __ cmpq(dest, LiteralInt64Address(value)); |
| 7478 | } |
| 7479 | } |
| 7480 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7481 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 7482 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7483 | GenerateIntCompare(lhs_reg, rhs); |
| 7484 | } |
| 7485 | |
| 7486 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7487 | if (rhs.IsConstant()) { |
| 7488 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7489 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7490 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7491 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7492 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7493 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7494 | } |
| 7495 | } |
| 7496 | |
| 7497 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 7498 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 7499 | if (rhs.IsConstant()) { |
| 7500 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 7501 | Compare64BitValue(lhs_reg, value); |
| 7502 | } else if (rhs.IsDoubleStackSlot()) { |
| 7503 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 7504 | } else { |
| 7505 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 7506 | } |
| 7507 | } |
| 7508 | |
| 7509 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 7510 | Location index, |
| 7511 | ScaleFactor scale, |
| 7512 | uint32_t data_offset) { |
| 7513 | return index.IsConstant() ? |
| 7514 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7515 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 7516 | } |
| 7517 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 7518 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 7519 | DCHECK(dest.IsDoubleStackSlot()); |
| 7520 | if (IsInt<32>(value)) { |
| 7521 | // Can move directly as an int32 constant. |
| 7522 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 7523 | Immediate(static_cast<int32_t>(value))); |
| 7524 | } else { |
| 7525 | Load64BitValue(CpuRegister(TMP), value); |
| 7526 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 7527 | } |
| 7528 | } |
| 7529 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7530 | /** |
| 7531 | * Class to handle late fixup of offsets into constant area. |
| 7532 | */ |
| 7533 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 7534 | public: |
| 7535 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 7536 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7537 | |
| 7538 | protected: |
| 7539 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7540 | |
| 7541 | CodeGeneratorX86_64* codegen_; |
| 7542 | |
| 7543 | private: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7544 | void Process(const MemoryRegion& region, int pos) override { |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7545 | // Patch the correct offset for the instruction. We use the address of the |
| 7546 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 7547 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7548 | int32_t relative_position = constant_offset - pos; |
| 7549 | |
| 7550 | // Patch in the right value. |
| 7551 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7552 | } |
| 7553 | |
| 7554 | // Location in constant area that the fixup refers to. |
| 7555 | size_t offset_into_constant_area_; |
| 7556 | }; |
| 7557 | |
| 7558 | /** |
| 7559 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7560 | * constant area. |
| 7561 | */ |
| 7562 | class JumpTableRIPFixup : public RIPFixup { |
| 7563 | public: |
| 7564 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 7565 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7566 | |
| 7567 | void CreateJumpTable() { |
| 7568 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7569 | |
| 7570 | // Ensure that the reference to the jump table has the correct offset. |
| 7571 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7572 | SetOffset(offset_in_constant_table); |
| 7573 | |
| 7574 | // Compute the offset from the start of the function to this jump table. |
| 7575 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7576 | |
| 7577 | // Populate the jump table with the correct values for the jump table. |
| 7578 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7579 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7580 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7581 | // The value that we want is the target offset - the position of the table. |
| 7582 | for (int32_t i = 0; i < num_entries; i++) { |
| 7583 | HBasicBlock* b = successors[i]; |
| 7584 | Label* l = codegen_->GetLabelOf(b); |
| 7585 | DCHECK(l->IsBound()); |
| 7586 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7587 | assembler->AppendInt32(offset_to_block); |
| 7588 | } |
| 7589 | } |
| 7590 | |
| 7591 | private: |
| 7592 | const HPackedSwitch* switch_instr_; |
| 7593 | }; |
| 7594 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7595 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7596 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7597 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7598 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7599 | // 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] | 7600 | assembler->Align(4, 0); |
| 7601 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7602 | |
| 7603 | // Populate any jump tables. |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7604 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7605 | jump_table->CreateJumpTable(); |
| 7606 | } |
| 7607 | |
| 7608 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7609 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7610 | } |
| 7611 | |
| 7612 | // And finish up. |
| 7613 | CodeGenerator::Finalize(allocator); |
| 7614 | } |
| 7615 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7616 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7617 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddDouble(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7618 | return Address::RIP(fixup); |
| 7619 | } |
| 7620 | |
| 7621 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7622 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddFloat(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7623 | return Address::RIP(fixup); |
| 7624 | } |
| 7625 | |
| 7626 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7627 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt32(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7628 | return Address::RIP(fixup); |
| 7629 | } |
| 7630 | |
| 7631 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7632 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt64(v)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7633 | return Address::RIP(fixup); |
| 7634 | } |
| 7635 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7636 | // TODO: trg as memory. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7637 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7638 | if (!trg.IsValid()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7639 | DCHECK_EQ(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7640 | return; |
| 7641 | } |
| 7642 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7643 | DCHECK_NE(type, DataType::Type::kVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7644 | |
| 7645 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7646 | if (trg.Equals(return_loc)) { |
| 7647 | return; |
| 7648 | } |
| 7649 | |
| 7650 | // Let the parallel move resolver take care of all of this. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7651 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7652 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7653 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7654 | } |
| 7655 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7656 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7657 | // Create a fixup to be used to create and address the jump table. |
| 7658 | JumpTableRIPFixup* table_fixup = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7659 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7660 | |
| 7661 | // We have to populate the jump tables. |
| 7662 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7663 | return Address::RIP(table_fixup); |
| 7664 | } |
| 7665 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7666 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7667 | const Address& addr_high, |
| 7668 | int64_t v, |
| 7669 | HInstruction* instruction) { |
| 7670 | if (IsInt<32>(v)) { |
| 7671 | int32_t v_32 = v; |
| 7672 | __ movq(addr_low, Immediate(v_32)); |
| 7673 | MaybeRecordImplicitNullCheck(instruction); |
| 7674 | } else { |
| 7675 | // Didn't fit in a register. Do it in pieces. |
| 7676 | int32_t low_v = Low32Bits(v); |
| 7677 | int32_t high_v = High32Bits(v); |
| 7678 | __ movl(addr_low, Immediate(low_v)); |
| 7679 | MaybeRecordImplicitNullCheck(instruction); |
| 7680 | __ movl(addr_high, Immediate(high_v)); |
| 7681 | } |
| 7682 | } |
| 7683 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7684 | void CodeGeneratorX86_64::PatchJitRootUse(uint8_t* code, |
| 7685 | const uint8_t* roots_data, |
| 7686 | const PatchInfo<Label>& info, |
| 7687 | uint64_t index_in_table) const { |
| 7688 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7689 | uintptr_t address = |
| 7690 | 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] | 7691 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7692 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7693 | dchecked_integral_cast<uint32_t>(address); |
| 7694 | } |
| 7695 | |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7696 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7697 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7698 | 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] | 7699 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7700 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7701 | } |
| 7702 | |
| 7703 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7704 | 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] | 7705 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7706 | PatchJitRootUse(code, roots_data, info, index_in_table); |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7707 | } |
| 7708 | } |
| 7709 | |
Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 7710 | bool LocationsBuilderX86_64::CpuHasAvxFeatureFlag() { |
| 7711 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 7712 | } |
| 7713 | |
| 7714 | bool LocationsBuilderX86_64::CpuHasAvx2FeatureFlag() { |
| 7715 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 7716 | } |
| 7717 | |
| 7718 | bool InstructionCodeGeneratorX86_64::CpuHasAvxFeatureFlag() { |
| 7719 | return codegen_->GetInstructionSetFeatures().HasAVX(); |
| 7720 | } |
| 7721 | |
| 7722 | bool InstructionCodeGeneratorX86_64::CpuHasAvx2FeatureFlag() { |
| 7723 | return codegen_->GetInstructionSetFeatures().HasAVX2(); |
| 7724 | } |
| 7725 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7726 | #undef __ |
| 7727 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7728 | } // namespace x86_64 |
| 7729 | } // namespace art |