| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86_64.h" |
| 18 | |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 20 | #include "class_table.h" |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 21 | #include "code_generator_utils.h" |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 25 | #include "gc/space/image_space.h" |
| Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 26 | #include "heap_poisoning.h" |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 27 | #include "intrinsics.h" |
| 28 | #include "intrinsics_x86_64.h" |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 29 | #include "linker/linker_patch.h" |
| Andreas Gampe | d490129 | 2017-05-30 18:41:34 -0700 | [diff] [blame] | 30 | #include "lock_word.h" |
| Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 31 | #include "mirror/array-inl.h" |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 32 | #include "mirror/class-inl.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 33 | #include "mirror/object_reference.h" |
| 34 | #include "thread.h" |
| 35 | #include "utils/assembler.h" |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 36 | #include "utils/stack_checks.h" |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 37 | #include "utils/x86_64/assembler_x86_64.h" |
| 38 | #include "utils/x86_64/managed_register_x86_64.h" |
| 39 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 40 | namespace art { |
| 41 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 42 | template<class MirrorType> |
| 43 | class GcRoot; |
| 44 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 45 | namespace x86_64 { |
| 46 | |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = RDI; |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 49 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 50 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 51 | // generates less code/data with a small num_entries. |
| 52 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 53 | |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 54 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 55 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 56 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 57 | static constexpr int kC2ConditionMask = 0x400; |
| 58 | |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 59 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 60 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 61 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 62 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 63 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 65 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 66 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 67 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 68 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 70 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 71 | // Live registers will be restored in the catch block if caught. |
| 72 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 73 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 74 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 75 | instruction_, |
| 76 | instruction_->GetDexPc(), |
| 77 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 78 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 81 | bool IsFatal() const OVERRIDE { return true; } |
| 82 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 83 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 84 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 85 | private: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 86 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 87 | }; |
| 88 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 89 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 91 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 92 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 93 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 94 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | __ Bind(GetEntryLabel()); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 96 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 97 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 100 | bool IsFatal() const OVERRIDE { return true; } |
| 101 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 102 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 103 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | private: |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 106 | }; |
| 107 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 108 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 110 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, DataType::Type type, bool is_div) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 111 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 113 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 114 | __ Bind(GetEntryLabel()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 115 | if (type_ == DataType::Type::kInt32) { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 116 | if (is_div_) { |
| 117 | __ negl(cpu_reg_); |
| 118 | } else { |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 119 | __ xorl(cpu_reg_, cpu_reg_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 122 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 123 | DCHECK_EQ(DataType::Type::kInt64, type_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 124 | if (is_div_) { |
| 125 | __ negq(cpu_reg_); |
| 126 | } else { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 127 | __ xorl(cpu_reg_, cpu_reg_); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 128 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 129 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 130 | __ jmp(GetExitLabel()); |
| 131 | } |
| 132 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 133 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 134 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 135 | private: |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 136 | const CpuRegister cpu_reg_; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 137 | const DataType::Type type_; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 138 | const bool is_div_; |
| 139 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 142 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 143 | public: |
| Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 144 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 145 | : SlowPathCode(instruction), successor_(successor) {} |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 146 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 147 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 148 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 149 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 150 | __ Bind(GetEntryLabel()); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 151 | SaveLiveRegisters(codegen, locations); // Only saves full width XMM for SIMD. |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 152 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 153 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 154 | RestoreLiveRegisters(codegen, locations); // Only restores full width XMM for SIMD. |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 155 | if (successor_ == nullptr) { |
| 156 | __ jmp(GetReturnLabel()); |
| 157 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 158 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 159 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 162 | Label* GetReturnLabel() { |
| 163 | DCHECK(successor_ == nullptr); |
| 164 | return &return_label_; |
| 165 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 166 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 167 | HBasicBlock* GetSuccessor() const { |
| 168 | return successor_; |
| 169 | } |
| 170 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 171 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 172 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 173 | private: |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 174 | HBasicBlock* const successor_; |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 175 | Label return_label_; |
| 176 | |
| 177 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 178 | }; |
| 179 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 180 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 181 | public: |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 182 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 183 | : SlowPathCode(instruction) {} |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 184 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 185 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 186 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 187 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 188 | __ Bind(GetEntryLabel()); |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 189 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 190 | // Live registers will be restored in the catch block if caught. |
| 191 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 192 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 193 | // Are we using an array length from memory? |
| 194 | HInstruction* array_length = instruction_->InputAt(1); |
| 195 | Location length_loc = locations->InAt(1); |
| 196 | InvokeRuntimeCallingConvention calling_convention; |
| 197 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 198 | // Load the array length into our temporary. |
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 199 | HArrayLength* length = array_length->AsArrayLength(); |
| Nicolas Geoffray | 003444a | 2017-10-17 10:58:42 +0100 | [diff] [blame] | 200 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 201 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 202 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 203 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 204 | // Check for conflicts with index. |
| 205 | if (length_loc.Equals(locations->InAt(0))) { |
| 206 | // We know we aren't using parameter 2. |
| 207 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 208 | } |
| 209 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 210 | if (mirror::kUseStringCompression && length->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 211 | __ shrl(length_loc.AsRegister<CpuRegister>(), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 212 | } |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 213 | } |
| 214 | |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 215 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 216 | // move resolver. |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 217 | codegen->EmitParallelMoves( |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 218 | locations->InAt(0), |
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 219 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 220 | DataType::Type::kInt32, |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 221 | length_loc, |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 222 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 223 | DataType::Type::kInt32); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 224 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 225 | ? kQuickThrowStringBounds |
| 226 | : kQuickThrowArrayBounds; |
| 227 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 228 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 229 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 230 | } |
| 231 | |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 232 | bool IsFatal() const OVERRIDE { return true; } |
| 233 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 234 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 235 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 236 | private: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 237 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 238 | }; |
| 239 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 240 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 241 | public: |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 242 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 243 | HInstruction* at, |
| 244 | uint32_t dex_pc, |
| 245 | bool do_clinit) |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 246 | : SlowPathCode(at), cls_(cls), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 247 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 248 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 249 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 250 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 251 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 252 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 253 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 254 | |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 255 | SaveLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 256 | |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 257 | // Custom calling convention: RAX serves as both input and output. |
| 258 | __ movl(CpuRegister(RAX), Immediate(cls_->GetTypeIndex().index_)); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 259 | x86_64_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage : kQuickInitializeType, |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 260 | instruction_, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 261 | dex_pc_, |
| 262 | this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 263 | if (do_clinit_) { |
| 264 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 265 | } else { |
| 266 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 267 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 268 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 269 | Location out = locations->Out(); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 270 | // Move the class to the desired location. |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 271 | if (out.IsValid()) { |
| 272 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 273 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 276 | RestoreLiveRegisters(codegen, locations); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 277 | __ jmp(GetExitLabel()); |
| 278 | } |
| 279 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 280 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 281 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 282 | private: |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 283 | // The class this slow path will load. |
| 284 | HLoadClass* const cls_; |
| 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 | // The dex PC of `at_`. |
| 287 | const uint32_t dex_pc_; |
| 288 | |
| 289 | // Whether to initialize the class. |
| 290 | const bool do_clinit_; |
| 291 | |
| 292 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 293 | }; |
| 294 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 295 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
| 296 | public: |
| 297 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
| 298 | |
| 299 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 300 | LocationSummary* locations = instruction_->GetLocations(); |
| 301 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 302 | |
| 303 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 304 | __ Bind(GetEntryLabel()); |
| 305 | SaveLiveRegisters(codegen, locations); |
| 306 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 307 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 308 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 309 | __ movl(CpuRegister(RAX), Immediate(string_index.index_)); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 310 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
| 311 | instruction_, |
| 312 | instruction_->GetDexPc(), |
| 313 | this); |
| 314 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 315 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 316 | RestoreLiveRegisters(codegen, locations); |
| 317 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 318 | __ jmp(GetExitLabel()); |
| 319 | } |
| 320 | |
| 321 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 322 | |
| 323 | private: |
| 324 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 325 | }; |
| 326 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 327 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 328 | public: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 329 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 330 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 331 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 332 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 333 | LocationSummary* locations = instruction_->GetLocations(); |
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 334 | uint32_t dex_pc = instruction_->GetDexPc(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 335 | DCHECK(instruction_->IsCheckCast() |
| 336 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 337 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 338 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 339 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 340 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 341 | if (kPoisonHeapReferences && |
| 342 | instruction_->IsCheckCast() && |
| 343 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { |
| 344 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. |
| 345 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<CpuRegister>()); |
| 346 | } |
| 347 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 348 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 349 | SaveLiveRegisters(codegen, locations); |
| 350 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 351 | |
| 352 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 353 | // move resolver. |
| 354 | InvokeRuntimeCallingConvention calling_convention; |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 355 | codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 356 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 357 | DataType::Type::kReference, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 358 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 359 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 360 | DataType::Type::kReference); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 361 | if (instruction_->IsInstanceOf()) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 362 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 363 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 364 | } else { |
| 365 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 366 | x86_64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this); |
| 367 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 368 | } |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 369 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 370 | if (!is_fatal_) { |
| 371 | if (instruction_->IsInstanceOf()) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 372 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 373 | } |
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 374 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 375 | RestoreLiveRegisters(codegen, locations); |
| 376 | __ jmp(GetExitLabel()); |
| 377 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 380 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 381 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 382 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 383 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 384 | private: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 385 | const bool is_fatal_; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 386 | |
| 387 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 388 | }; |
| 389 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 390 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 391 | public: |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 392 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 393 | : SlowPathCode(instruction) {} |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 394 | |
| 395 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 396 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 397 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 398 | LocationSummary* locations = instruction_->GetLocations(); |
| 399 | SaveLiveRegisters(codegen, locations); |
| 400 | InvokeRuntimeCallingConvention calling_convention; |
| 401 | x86_64_codegen->Load32BitValue( |
| 402 | CpuRegister(calling_convention.GetRegisterAt(0)), |
| 403 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 404 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 405 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 408 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 409 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 410 | private: |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 411 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 412 | }; |
| 413 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 414 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 415 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 416 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 417 | |
| 418 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 419 | LocationSummary* locations = instruction_->GetLocations(); |
| 420 | __ Bind(GetEntryLabel()); |
| 421 | SaveLiveRegisters(codegen, locations); |
| 422 | |
| 423 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 424 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 425 | parallel_move.AddMove( |
| 426 | locations->InAt(0), |
| 427 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 428 | DataType::Type::kReference, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 429 | nullptr); |
| 430 | parallel_move.AddMove( |
| 431 | locations->InAt(1), |
| 432 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 433 | DataType::Type::kInt32, |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 434 | nullptr); |
| 435 | parallel_move.AddMove( |
| 436 | locations->InAt(2), |
| 437 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 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 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 441 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 442 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 443 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 444 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 445 | RestoreLiveRegisters(codegen, locations); |
| 446 | __ jmp(GetExitLabel()); |
| 447 | } |
| 448 | |
| 449 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 450 | |
| 451 | private: |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 452 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 453 | }; |
| 454 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 455 | // Slow path marking an object reference `ref` during a read |
| 456 | // barrier. The field `obj.field` in the object `obj` holding this |
| 457 | // reference does not get updated by this slow path after marking (see |
| 458 | // ReadBarrierMarkAndUpdateFieldSlowPathX86_64 below for that). |
| 459 | // |
| 460 | // This means that after the execution of this slow path, `ref` will |
| 461 | // always be up-to-date, but `obj.field` may not; i.e., after the |
| 462 | // flip, `ref` will be a to-space reference, but `obj.field` will |
| 463 | // probably still be a from-space reference (unless it gets updated by |
| 464 | // another thread, or if another thread installed another object |
| 465 | // reference (different from `ref`) in `obj.field`). |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 466 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 467 | public: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 468 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, |
| 469 | Location ref, |
| 470 | bool unpoison_ref_before_marking) |
| 471 | : SlowPathCode(instruction), |
| 472 | ref_(ref), |
| 473 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 474 | DCHECK(kEmitCompilerReadBarrier); |
| 475 | } |
| 476 | |
| 477 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 478 | |
| 479 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 480 | LocationSummary* locations = instruction_->GetLocations(); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 481 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 482 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 483 | DCHECK(locations->CanCall()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 484 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 485 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 486 | instruction_->IsStaticFieldGet() || |
| 487 | instruction_->IsArrayGet() || |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 488 | instruction_->IsArraySet() || |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 489 | instruction_->IsLoadClass() || |
| 490 | instruction_->IsLoadString() || |
| 491 | instruction_->IsInstanceOf() || |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 492 | instruction_->IsCheckCast() || |
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 493 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 494 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 495 | << "Unexpected instruction in read barrier marking slow path: " |
| 496 | << instruction_->DebugName(); |
| 497 | |
| 498 | __ Bind(GetEntryLabel()); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 499 | if (unpoison_ref_before_marking_) { |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 500 | // Object* ref = ref_addr->AsMirrorPtr() |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 501 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 502 | } |
| Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 503 | // No need to save live registers; it's taken care of by the |
| 504 | // entrypoint. Also, there is no need to update the stack mask, |
| 505 | // as this runtime call will not trigger a garbage collection. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 506 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 507 | DCHECK_NE(ref_reg, RSP); |
| 508 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 509 | // "Compact" slow path, saving two moves. |
| 510 | // |
| 511 | // Instead of using the standard runtime calling convention (input |
| 512 | // and output in R0): |
| 513 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 514 | // RDI <- ref |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 515 | // RAX <- ReadBarrierMark(RDI) |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 516 | // ref <- RAX |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 517 | // |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 518 | // we just use rX (the register containing `ref`) as input and output |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 519 | // of a dedicated entrypoint: |
| 520 | // |
| 521 | // rX <- ReadBarrierMarkRegX(rX) |
| 522 | // |
| 523 | int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 524 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 525 | // This runtime call does not require a stack map. |
| 526 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 527 | __ jmp(GetExitLabel()); |
| 528 | } |
| 529 | |
| 530 | private: |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 531 | // The location (register) of the marked object reference. |
| 532 | const Location ref_; |
| 533 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 534 | const bool unpoison_ref_before_marking_; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 535 | |
| 536 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 537 | }; |
| 538 | |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 539 | // Slow path marking an object reference `ref` during a read barrier, |
| 540 | // and if needed, atomically updating the field `obj.field` in the |
| 541 | // object `obj` holding this reference after marking (contrary to |
| 542 | // ReadBarrierMarkSlowPathX86_64 above, which never tries to update |
| 543 | // `obj.field`). |
| 544 | // |
| 545 | // This means that after the execution of this slow path, both `ref` |
| 546 | // and `obj.field` will be up-to-date; i.e., after the flip, both will |
| 547 | // hold the same to-space reference (unless another thread installed |
| 548 | // another object reference (different from `ref`) in `obj.field`). |
| 549 | class ReadBarrierMarkAndUpdateFieldSlowPathX86_64 : public SlowPathCode { |
| 550 | public: |
| 551 | ReadBarrierMarkAndUpdateFieldSlowPathX86_64(HInstruction* instruction, |
| 552 | Location ref, |
| 553 | CpuRegister obj, |
| 554 | const Address& field_addr, |
| 555 | bool unpoison_ref_before_marking, |
| 556 | CpuRegister temp1, |
| 557 | CpuRegister temp2) |
| 558 | : SlowPathCode(instruction), |
| 559 | ref_(ref), |
| 560 | obj_(obj), |
| 561 | field_addr_(field_addr), |
| 562 | unpoison_ref_before_marking_(unpoison_ref_before_marking), |
| 563 | temp1_(temp1), |
| 564 | temp2_(temp2) { |
| 565 | DCHECK(kEmitCompilerReadBarrier); |
| 566 | } |
| 567 | |
| 568 | const char* GetDescription() const OVERRIDE { |
| 569 | return "ReadBarrierMarkAndUpdateFieldSlowPathX86_64"; |
| 570 | } |
| 571 | |
| 572 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 573 | LocationSummary* locations = instruction_->GetLocations(); |
| 574 | CpuRegister ref_cpu_reg = ref_.AsRegister<CpuRegister>(); |
| 575 | Register ref_reg = ref_cpu_reg.AsRegister(); |
| 576 | DCHECK(locations->CanCall()); |
| 577 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; |
| 578 | // This slow path is only used by the UnsafeCASObject intrinsic. |
| 579 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| 580 | << "Unexpected instruction in read barrier marking and field updating slow path: " |
| 581 | << instruction_->DebugName(); |
| 582 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 583 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); |
| 584 | |
| 585 | __ Bind(GetEntryLabel()); |
| 586 | if (unpoison_ref_before_marking_) { |
| 587 | // Object* ref = ref_addr->AsMirrorPtr() |
| 588 | __ MaybeUnpoisonHeapReference(ref_cpu_reg); |
| 589 | } |
| 590 | |
| 591 | // Save the old (unpoisoned) reference. |
| 592 | __ movl(temp1_, ref_cpu_reg); |
| 593 | |
| 594 | // No need to save live registers; it's taken care of by the |
| 595 | // entrypoint. Also, there is no need to update the stack mask, |
| 596 | // as this runtime call will not trigger a garbage collection. |
| 597 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 598 | DCHECK_NE(ref_reg, RSP); |
| 599 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; |
| 600 | // "Compact" slow path, saving two moves. |
| 601 | // |
| 602 | // Instead of using the standard runtime calling convention (input |
| 603 | // and output in R0): |
| 604 | // |
| 605 | // RDI <- ref |
| 606 | // RAX <- ReadBarrierMark(RDI) |
| 607 | // ref <- RAX |
| 608 | // |
| 609 | // we just use rX (the register containing `ref`) as input and output |
| 610 | // of a dedicated entrypoint: |
| 611 | // |
| 612 | // rX <- ReadBarrierMarkRegX(rX) |
| 613 | // |
| 614 | int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 615 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(ref_reg); |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 616 | // This runtime call does not require a stack map. |
| 617 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 618 | |
| 619 | // If the new reference is different from the old reference, |
| 620 | // update the field in the holder (`*field_addr`). |
| 621 | // |
| 622 | // Note that this field could also hold a different object, if |
| 623 | // another thread had concurrently changed it. In that case, the |
| 624 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) |
| 625 | // operation below would abort the CAS, leaving the field as-is. |
| 626 | NearLabel done; |
| 627 | __ cmpl(temp1_, ref_cpu_reg); |
| 628 | __ j(kEqual, &done); |
| 629 | |
| 630 | // Update the the holder's field atomically. This may fail if |
| 631 | // mutator updates before us, but it's OK. This is achived |
| 632 | // using a strong compare-and-set (CAS) operation with relaxed |
| 633 | // memory synchronization ordering, where the expected value is |
| 634 | // the old reference and the desired value is the new reference. |
| 635 | // This operation is implemented with a 32-bit LOCK CMPXLCHG |
| 636 | // instruction, which requires the expected value (the old |
| 637 | // reference) to be in EAX. Save RAX beforehand, and move the |
| 638 | // expected value (stored in `temp1_`) into EAX. |
| 639 | __ movq(temp2_, CpuRegister(RAX)); |
| 640 | __ movl(CpuRegister(RAX), temp1_); |
| 641 | |
| 642 | // Convenience aliases. |
| 643 | CpuRegister base = obj_; |
| 644 | CpuRegister expected = CpuRegister(RAX); |
| 645 | CpuRegister value = ref_cpu_reg; |
| 646 | |
| 647 | bool base_equals_value = (base.AsRegister() == value.AsRegister()); |
| 648 | Register value_reg = ref_reg; |
| 649 | if (kPoisonHeapReferences) { |
| 650 | if (base_equals_value) { |
| 651 | // If `base` and `value` are the same register location, move |
| 652 | // `value_reg` to a temporary register. This way, poisoning |
| 653 | // `value_reg` won't invalidate `base`. |
| 654 | value_reg = temp1_.AsRegister(); |
| 655 | __ movl(CpuRegister(value_reg), base); |
| 656 | } |
| 657 | |
| 658 | // Check that the register allocator did not assign the location |
| 659 | // of `expected` (RAX) to `value` nor to `base`, so that heap |
| 660 | // poisoning (when enabled) works as intended below. |
| 661 | // - If `value` were equal to `expected`, both references would |
| 662 | // be poisoned twice, meaning they would not be poisoned at |
| 663 | // all, as heap poisoning uses address negation. |
| 664 | // - If `base` were equal to `expected`, poisoning `expected` |
| 665 | // would invalidate `base`. |
| 666 | DCHECK_NE(value_reg, expected.AsRegister()); |
| 667 | DCHECK_NE(base.AsRegister(), expected.AsRegister()); |
| 668 | |
| 669 | __ PoisonHeapReference(expected); |
| 670 | __ PoisonHeapReference(CpuRegister(value_reg)); |
| 671 | } |
| 672 | |
| 673 | __ LockCmpxchgl(field_addr_, CpuRegister(value_reg)); |
| 674 | |
| 675 | // If heap poisoning is enabled, we need to unpoison the values |
| 676 | // that were poisoned earlier. |
| 677 | if (kPoisonHeapReferences) { |
| 678 | if (base_equals_value) { |
| 679 | // `value_reg` has been moved to a temporary register, no need |
| 680 | // to unpoison it. |
| 681 | } else { |
| 682 | __ UnpoisonHeapReference(CpuRegister(value_reg)); |
| 683 | } |
| 684 | // No need to unpoison `expected` (RAX), as it is be overwritten below. |
| 685 | } |
| 686 | |
| 687 | // Restore RAX. |
| 688 | __ movq(CpuRegister(RAX), temp2_); |
| 689 | |
| 690 | __ Bind(&done); |
| 691 | __ jmp(GetExitLabel()); |
| 692 | } |
| 693 | |
| 694 | private: |
| 695 | // The location (register) of the marked object reference. |
| 696 | const Location ref_; |
| 697 | // The register containing the object holding the marked object reference field. |
| 698 | const CpuRegister obj_; |
| 699 | // The address of the marked reference field. The base of this address must be `obj_`. |
| 700 | const Address field_addr_; |
| 701 | |
| 702 | // Should the reference in `ref_` be unpoisoned prior to marking it? |
| 703 | const bool unpoison_ref_before_marking_; |
| 704 | |
| 705 | const CpuRegister temp1_; |
| 706 | const CpuRegister temp2_; |
| 707 | |
| 708 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86_64); |
| 709 | }; |
| 710 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 711 | // Slow path generating a read barrier for a heap reference. |
| 712 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 713 | public: |
| 714 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 715 | Location out, |
| 716 | Location ref, |
| 717 | Location obj, |
| 718 | uint32_t offset, |
| 719 | Location index) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 720 | : SlowPathCode(instruction), |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 721 | out_(out), |
| 722 | ref_(ref), |
| 723 | obj_(obj), |
| 724 | offset_(offset), |
| 725 | index_(index) { |
| 726 | DCHECK(kEmitCompilerReadBarrier); |
| 727 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 728 | // object has been overwritten by (or after) the heap object |
| 729 | // reference load to be instrumented, e.g.: |
| 730 | // |
| 731 | // __ movl(out, Address(out, offset)); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 732 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 733 | // |
| 734 | // In that case, we have lost the information about the original |
| 735 | // object, and the emitted read barrier cannot work properly. |
| 736 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 737 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 738 | } |
| 739 | |
| 740 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 741 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 742 | LocationSummary* locations = instruction_->GetLocations(); |
| 743 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 744 | DCHECK(locations->CanCall()); |
| 745 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 746 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 747 | instruction_->IsStaticFieldGet() || |
| 748 | instruction_->IsArrayGet() || |
| 749 | instruction_->IsInstanceOf() || |
| 750 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 751 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 752 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 753 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 754 | |
| 755 | __ Bind(GetEntryLabel()); |
| 756 | SaveLiveRegisters(codegen, locations); |
| 757 | |
| 758 | // We may have to change the index's value, but as `index_` is a |
| 759 | // constant member (like other "inputs" of this slow path), |
| 760 | // introduce a copy of it, `index`. |
| 761 | Location index = index_; |
| 762 | if (index_.IsValid()) { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 763 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 764 | if (instruction_->IsArrayGet()) { |
| 765 | // Compute real offset and store it in index_. |
| 766 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 767 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 768 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 769 | // We are about to change the value of `index_reg` (see the |
| 770 | // calls to art::x86_64::X86_64Assembler::shll and |
| 771 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 772 | // has not been saved by the previous call to |
| 773 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 774 | // callee-save register -- |
| 775 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 776 | // callee-save registers, as it has been designed with the |
| 777 | // assumption that callee-save registers are supposed to be |
| 778 | // handled by the called function. So, as a callee-save |
| 779 | // register, `index_reg` _would_ eventually be saved onto |
| 780 | // the stack, but it would be too late: we would have |
| 781 | // changed its value earlier. Therefore, we manually save |
| 782 | // it here into another freely available register, |
| 783 | // `free_reg`, chosen of course among the caller-save |
| 784 | // registers (as a callee-save `free_reg` register would |
| 785 | // exhibit the same problem). |
| 786 | // |
| 787 | // Note we could have requested a temporary register from |
| 788 | // the register allocator instead; but we prefer not to, as |
| 789 | // this is a slow path, and we know we can find a |
| 790 | // caller-save register that is available. |
| 791 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 792 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 793 | index_reg = free_reg; |
| 794 | index = Location::RegisterLocation(index_reg); |
| 795 | } else { |
| 796 | // The initial register stored in `index_` has already been |
| 797 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 798 | // (as it is not a callee-save register), so we can freely |
| 799 | // use it. |
| 800 | } |
| 801 | // Shifting the index value contained in `index_reg` by the |
| 802 | // scale factor (2) cannot overflow in practice, as the |
| 803 | // runtime is unable to allocate object arrays with a size |
| 804 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 805 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 806 | static_assert( |
| 807 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 808 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 809 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 810 | } else { |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 811 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 812 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 813 | // (as in the case of ArrayGet), as it is actually an offset |
| 814 | // to an object field within an object. |
| 815 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 816 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 817 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 818 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 819 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 820 | DCHECK_EQ(offset_, 0U); |
| 821 | DCHECK(index_.IsRegister()); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | // We're moving two or three locations to locations that could |
| 826 | // overlap, so we need a parallel move resolver. |
| 827 | InvokeRuntimeCallingConvention calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 828 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 829 | parallel_move.AddMove(ref_, |
| 830 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 831 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 832 | nullptr); |
| 833 | parallel_move.AddMove(obj_, |
| 834 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 835 | DataType::Type::kReference, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 836 | nullptr); |
| 837 | if (index.IsValid()) { |
| 838 | parallel_move.AddMove(index, |
| 839 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 840 | DataType::Type::kInt32, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 841 | nullptr); |
| 842 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 843 | } else { |
| 844 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 845 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 846 | } |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 847 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 848 | instruction_, |
| 849 | instruction_->GetDexPc(), |
| 850 | this); |
| 851 | CheckEntrypointTypes< |
| 852 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 853 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 854 | |
| 855 | RestoreLiveRegisters(codegen, locations); |
| 856 | __ jmp(GetExitLabel()); |
| 857 | } |
| 858 | |
| 859 | const char* GetDescription() const OVERRIDE { |
| 860 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 861 | } |
| 862 | |
| 863 | private: |
| 864 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 865 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 866 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 867 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 868 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 869 | return static_cast<CpuRegister>(i); |
| 870 | } |
| 871 | } |
| 872 | // We shall never fail to find a free caller-save register, as |
| 873 | // there are more than two core caller-save registers on x86-64 |
| 874 | // (meaning it is possible to find one which is different from |
| 875 | // `ref` and `obj`). |
| 876 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 877 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 878 | UNREACHABLE(); |
| 879 | } |
| 880 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 881 | const Location out_; |
| 882 | const Location ref_; |
| 883 | const Location obj_; |
| 884 | const uint32_t offset_; |
| 885 | // An additional location containing an index to an array. |
| 886 | // Only used for HArrayGet and the UnsafeGetObject & |
| 887 | // UnsafeGetObjectVolatile intrinsics. |
| 888 | const Location index_; |
| 889 | |
| 890 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 891 | }; |
| 892 | |
| 893 | // Slow path generating a read barrier for a GC root. |
| 894 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 895 | public: |
| 896 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 897 | : SlowPathCode(instruction), out_(out), root_(root) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 898 | DCHECK(kEmitCompilerReadBarrier); |
| 899 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 900 | |
| 901 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 902 | LocationSummary* locations = instruction_->GetLocations(); |
| 903 | DCHECK(locations->CanCall()); |
| 904 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 905 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 906 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 907 | << instruction_->DebugName(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 908 | |
| 909 | __ Bind(GetEntryLabel()); |
| 910 | SaveLiveRegisters(codegen, locations); |
| 911 | |
| 912 | InvokeRuntimeCallingConvention calling_convention; |
| 913 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 914 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 915 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 916 | instruction_, |
| 917 | instruction_->GetDexPc(), |
| 918 | this); |
| 919 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 920 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 921 | |
| 922 | RestoreLiveRegisters(codegen, locations); |
| 923 | __ jmp(GetExitLabel()); |
| 924 | } |
| 925 | |
| 926 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 927 | |
| 928 | private: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 929 | const Location out_; |
| 930 | const Location root_; |
| 931 | |
| 932 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 933 | }; |
| 934 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 935 | #undef __ |
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 936 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 937 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 938 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 939 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 940 | switch (cond) { |
| 941 | case kCondEQ: return kEqual; |
| 942 | case kCondNE: return kNotEqual; |
| 943 | case kCondLT: return kLess; |
| 944 | case kCondLE: return kLessEqual; |
| 945 | case kCondGT: return kGreater; |
| 946 | case kCondGE: return kGreaterEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 947 | case kCondB: return kBelow; |
| 948 | case kCondBE: return kBelowEqual; |
| 949 | case kCondA: return kAbove; |
| 950 | case kCondAE: return kAboveEqual; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 951 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 952 | LOG(FATAL) << "Unreachable"; |
| 953 | UNREACHABLE(); |
| 954 | } |
| 955 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 956 | // Maps FP condition to x86_64 name. |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 957 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 958 | switch (cond) { |
| 959 | case kCondEQ: return kEqual; |
| 960 | case kCondNE: return kNotEqual; |
| 961 | case kCondLT: return kBelow; |
| 962 | case kCondLE: return kBelowEqual; |
| 963 | case kCondGT: return kAbove; |
| 964 | case kCondGE: return kAboveEqual; |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 965 | default: break; // should not happen |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 966 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 967 | LOG(FATAL) << "Unreachable"; |
| 968 | UNREACHABLE(); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 969 | } |
| 970 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 971 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 972 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 973 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | c1a42cf | 2016-12-18 15:52:36 +0000 | [diff] [blame] | 974 | return desired_dispatch_info; |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 975 | } |
| 976 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 977 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall( |
| 978 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 979 | // All registers are assumed to be correctly set up. |
| Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 980 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 981 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 982 | switch (invoke->GetMethodLoadKind()) { |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 983 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 984 | // temp = thread->string_init_entrypoint |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 985 | uint32_t offset = |
| 986 | GetThreadOffset<kX86_64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 987 | __ gs()->movq(temp.AsRegister<CpuRegister>(), Address::Absolute(offset, /* no_rip */ true)); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 988 | break; |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 989 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 990 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 991 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 992 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 993 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: |
| 994 | DCHECK(GetCompilerOptions().IsBootImage()); |
| 995 | __ leal(temp.AsRegister<CpuRegister>(), |
| 996 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 997 | RecordBootImageMethodPatch(invoke); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 998 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 999 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| Vladimir Marko | 2d73f33 | 2017-03-16 15:55:49 +0000 | [diff] [blame] | 1000 | Load64BitValue(temp.AsRegister<CpuRegister>(), invoke->GetMethodAddress()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1001 | break; |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1002 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| 1003 | // Note: Boot image is in the low 4GiB and the entry is 32-bit, so emit a 32-bit load. |
| 1004 | __ movl(temp.AsRegister<CpuRegister>(), |
| 1005 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1006 | RecordBootImageRelRoPatch(GetBootImageOffset(invoke)); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1007 | break; |
| 1008 | } |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1009 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1010 | __ movq(temp.AsRegister<CpuRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 1011 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1012 | RecordMethodBssEntryPatch(invoke); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1013 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1014 | } |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1015 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 1016 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 1017 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 1018 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | switch (invoke->GetCodePtrLocation()) { |
| 1022 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 1023 | __ call(&frame_entry_label_); |
| 1024 | break; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1025 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 1026 | // (callee_method + offset_of_quick_compiled_code)() |
| 1027 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 1028 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1029 | kX86_64PointerSize).SizeValue())); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1030 | break; |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1031 | } |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1032 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1033 | |
| 1034 | DCHECK(!IsLeafMethod()); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1035 | } |
| 1036 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1037 | void CodeGeneratorX86_64::GenerateVirtualCall( |
| 1038 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1039 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 1040 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1041 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1042 | |
| 1043 | // Use the calling convention instead of the location of the receiver, as |
| 1044 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 1045 | // slow path, the arguments have been moved to the right place, so here we are |
| 1046 | // guaranteed that the receiver is the first register of the calling convention. |
| 1047 | InvokeDexCallingConvention calling_convention; |
| 1048 | Register receiver = calling_convention.GetRegisterAt(0); |
| 1049 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1050 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1051 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1052 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1053 | MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1054 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 1055 | // emit a read barrier for the previous class reference load. |
| 1056 | // However this is not required in practice, as this is an |
| 1057 | // intermediate/temporary reference and because the current |
| 1058 | // concurrent copying collector keeps the from-space memory |
| 1059 | // intact/accessible until the end of the marking phase (the |
| 1060 | // concurrent copying collector may not in the future). |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1061 | __ MaybeUnpoisonHeapReference(temp); |
| 1062 | // temp = temp->GetMethodAt(method_offset); |
| 1063 | __ movq(temp, Address(temp, method_offset)); |
| 1064 | // call temp->GetEntryPoint(); |
| 1065 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1066 | kX86_64PointerSize).SizeValue())); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 1067 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1070 | void CodeGeneratorX86_64::RecordBootImageIntrinsicPatch(uint32_t intrinsic_data) { |
| 1071 | boot_image_intrinsic_patches_.emplace_back(/* target_dex_file */ nullptr, intrinsic_data); |
| 1072 | __ Bind(&boot_image_intrinsic_patches_.back().label); |
| 1073 | } |
| 1074 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1075 | void CodeGeneratorX86_64::RecordBootImageRelRoPatch(uint32_t boot_image_offset) { |
| 1076 | boot_image_method_patches_.emplace_back(/* target_dex_file */ nullptr, boot_image_offset); |
| 1077 | __ Bind(&boot_image_method_patches_.back().label); |
| 1078 | } |
| 1079 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1080 | void CodeGeneratorX86_64::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { |
| 1081 | boot_image_method_patches_.emplace_back( |
| 1082 | invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1083 | __ Bind(&boot_image_method_patches_.back().label); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1086 | void CodeGeneratorX86_64::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { |
| 1087 | method_bss_entry_patches_.emplace_back(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); |
| 1088 | __ Bind(&method_bss_entry_patches_.back().label); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1091 | void CodeGeneratorX86_64::RecordBootImageTypePatch(HLoadClass* load_class) { |
| 1092 | boot_image_type_patches_.emplace_back( |
| 1093 | &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1094 | __ Bind(&boot_image_type_patches_.back().label); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1095 | } |
| 1096 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1097 | Label* CodeGeneratorX86_64::NewTypeBssEntryPatch(HLoadClass* load_class) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1098 | type_bss_entry_patches_.emplace_back( |
| 1099 | &load_class->GetDexFile(), load_class->GetTypeIndex().index_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1100 | return &type_bss_entry_patches_.back().label; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1103 | void CodeGeneratorX86_64::RecordBootImageStringPatch(HLoadString* load_string) { |
| 1104 | boot_image_string_patches_.emplace_back( |
| 1105 | &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| 1106 | __ Bind(&boot_image_string_patches_.back().label); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1107 | } |
| 1108 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1109 | Label* CodeGeneratorX86_64::NewStringBssEntryPatch(HLoadString* load_string) { |
| 1110 | DCHECK(!GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1111 | string_bss_entry_patches_.emplace_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1112 | &load_string->GetDexFile(), load_string->GetStringIndex().index_); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 1113 | return &string_bss_entry_patches_.back().label; |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1116 | void CodeGeneratorX86_64::LoadBootImageAddress(CpuRegister reg, uint32_t boot_image_reference) { |
| 1117 | if (GetCompilerOptions().IsBootImage()) { |
| 1118 | __ leal(reg, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 1119 | RecordBootImageIntrinsicPatch(boot_image_reference); |
| 1120 | } else if (GetCompilerOptions().GetCompilePic()) { |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1121 | DCHECK(Runtime::Current()->IsAotCompiler()); |
| 1122 | __ movl(reg, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1123 | RecordBootImageRelRoPatch(boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1124 | } else { |
| 1125 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 1126 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1127 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 1128 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); |
| 1129 | } |
| 1130 | } |
| 1131 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1132 | void CodeGeneratorX86_64::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 1133 | uint32_t boot_image_offset) { |
| 1134 | DCHECK(invoke->IsStatic()); |
| 1135 | InvokeRuntimeCallingConvention calling_convention; |
| 1136 | CpuRegister argument = CpuRegister(calling_convention.GetRegisterAt(0)); |
| 1137 | if (GetCompilerOptions().IsBootImage()) { |
| 1138 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 1139 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 1140 | __ leal(argument, |
| 1141 | Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 1142 | MethodReference target_method = invoke->GetTargetMethod(); |
| 1143 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 1144 | boot_image_type_patches_.emplace_back(target_method.dex_file, type_idx.index_); |
| 1145 | __ Bind(&boot_image_type_patches_.back().label); |
| 1146 | } else { |
| 1147 | LoadBootImageAddress(argument, boot_image_offset); |
| 1148 | } |
| 1149 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 1150 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 1151 | } |
| 1152 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1153 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 1154 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 1155 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 1156 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1157 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1158 | inline void CodeGeneratorX86_64::EmitPcRelativeLinkerPatches( |
| 1159 | const ArenaDeque<PatchInfo<Label>>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1160 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 1161 | for (const PatchInfo<Label>& info : infos) { |
| 1162 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 1163 | linker_patches->push_back( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1164 | 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] | 1165 | } |
| 1166 | } |
| 1167 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1168 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 1169 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 1170 | const DexFile* target_dex_file, |
| 1171 | uint32_t pc_insn_offset, |
| 1172 | uint32_t boot_image_offset) { |
| 1173 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 1174 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1177 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1178 | DCHECK(linker_patches->empty()); |
| 1179 | size_t size = |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1180 | boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1181 | method_bss_entry_patches_.size() + |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1182 | boot_image_type_patches_.size() + |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 1183 | type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1184 | boot_image_string_patches_.size() + |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1185 | string_bss_entry_patches_.size() + |
| 1186 | boot_image_intrinsic_patches_.size(); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1187 | linker_patches->reserve(size); |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1188 | if (GetCompilerOptions().IsBootImage()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1189 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| 1190 | boot_image_method_patches_, linker_patches); |
| 1191 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| 1192 | boot_image_type_patches_, linker_patches); |
| 1193 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1194 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1195 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 1196 | boot_image_intrinsic_patches_, linker_patches); |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 1197 | } else { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1198 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 1199 | boot_image_method_patches_, linker_patches); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 1200 | DCHECK(boot_image_type_patches_.empty()); |
| 1201 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1202 | DCHECK(boot_image_intrinsic_patches_.empty()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1203 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 1204 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 1205 | method_bss_entry_patches_, linker_patches); |
| 1206 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 1207 | type_bss_entry_patches_, linker_patches); |
| 1208 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 1209 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1210 | DCHECK_EQ(size, linker_patches->size()); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1213 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1214 | stream << Register(reg); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 1218 | stream << FloatRegister(reg); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1219 | } |
| 1220 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1221 | const X86_64InstructionSetFeatures& CodeGeneratorX86_64::GetInstructionSetFeatures() const { |
| 1222 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86_64InstructionSetFeatures(); |
| 1223 | } |
| 1224 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1225 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1226 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 1227 | return kX86_64WordSize; |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1228 | } |
| 1229 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1230 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 1231 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1232 | return kX86_64WordSize; |
| 1233 | } |
| 1234 | |
| 1235 | 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] | 1236 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1237 | __ movups(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1238 | } else { |
| 1239 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1240 | } |
| 1241 | return GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | 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] | 1245 | if (GetGraph()->HasSIMD()) { |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 1246 | __ movups(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 1247 | } else { |
| 1248 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1249 | } |
| 1250 | return GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1251 | } |
| 1252 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1253 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1254 | HInstruction* instruction, |
| 1255 | uint32_t dex_pc, |
| 1256 | SlowPathCode* slow_path) { |
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1257 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1258 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1259 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1260 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1261 | } |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1262 | } |
| 1263 | |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1264 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1265 | HInstruction* instruction, |
| 1266 | SlowPathCode* slow_path) { |
| 1267 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1268 | GenerateInvokeRuntime(entry_point_offset); |
| 1269 | } |
| 1270 | |
| 1271 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1272 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
| 1273 | } |
| 1274 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1275 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1276 | // Use a fake return address register to mimic Quick. |
| 1277 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1278 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1279 | const CompilerOptions& compiler_options, |
| 1280 | OptimizingCompilerStats* stats) |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1281 | : CodeGenerator(graph, |
| 1282 | kNumberOfCpuRegisters, |
| 1283 | kNumberOfFloatRegisters, |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1284 | kNumberOfCpuRegisterPairs, |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1285 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1286 | arraysize(kCoreCalleeSaves)) |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1287 | | (1 << kFakeReturnRegister), |
| Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1288 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1289 | arraysize(kFpuCalleeSaves)), |
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1290 | compiler_options, |
| 1291 | stats), |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1292 | block_labels_(nullptr), |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1293 | location_builder_(graph, this), |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1294 | instruction_visitor_(graph, this), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1295 | move_resolver_(graph->GetAllocator(), this), |
| 1296 | assembler_(graph->GetAllocator()), |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1297 | constant_area_start_(0), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1298 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1299 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1300 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1301 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1302 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1303 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1304 | boot_image_intrinsic_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1305 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1306 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1307 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1308 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1309 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1310 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1311 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1312 | CodeGeneratorX86_64* codegen) |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1313 | : InstructionCodeGenerator(graph, codegen), |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1314 | assembler_(codegen->GetAssembler()), |
| 1315 | codegen_(codegen) {} |
| 1316 | |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1317 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1318 | // Stack register is always reserved. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1319 | blocked_core_registers_[RSP] = true; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1320 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1321 | // Block the register used as TMP. |
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1322 | blocked_core_registers_[TMP] = true; |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1323 | } |
| 1324 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1325 | static dwarf::Reg DWARFReg(Register reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1326 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1327 | } |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1328 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1329 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1330 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1331 | } |
| 1332 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1333 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1334 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1335 | __ Bind(&frame_entry_label_); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1336 | bool skip_overflow_check = IsLeafMethod() |
| Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1337 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1338 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1339 | |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1340 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1341 | __ addw(Address(CpuRegister(kMethodRegisterArgument), |
| 1342 | ArtMethod::HotnessCountOffset().Int32Value()), |
| 1343 | Immediate(1)); |
| 1344 | } |
| 1345 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1346 | if (!skip_overflow_check) { |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1347 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86_64); |
| 1348 | __ testq(CpuRegister(RAX), Address(CpuRegister(RSP), -static_cast<int32_t>(reserved_bytes))); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1349 | RecordPcInfo(nullptr, 0); |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1350 | } |
| Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1351 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1352 | if (HasEmptyFrame()) { |
| 1353 | return; |
| 1354 | } |
| 1355 | |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1356 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1357 | Register reg = kCoreCalleeSaves[i]; |
| Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1358 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1359 | __ pushq(CpuRegister(reg)); |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1360 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1361 | __ cfi().RelOffset(DWARFReg(reg), 0); |
| Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1362 | } |
| 1363 | } |
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1364 | |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1365 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1366 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1367 | __ cfi().AdjustCFAOffset(adjust); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1368 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1369 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1370 | |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1371 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1372 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1373 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1374 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1375 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1376 | } |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1377 | } |
| 1378 | |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1379 | // Save the current method if we need it. Note that we do not |
| 1380 | // do this in HCurrentMethod, as the instruction might have been removed |
| 1381 | // in the SSA graph. |
| 1382 | if (RequiresCurrentMethod()) { |
| 1383 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
| 1384 | CpuRegister(kMethodRegisterArgument)); |
| 1385 | } |
| Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1386 | |
| 1387 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 1388 | // Initialize should_deoptimize flag to 0. |
| 1389 | __ movl(Address(CpuRegister(RSP), GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); |
| 1390 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | void CodeGeneratorX86_64::GenerateFrameExit() { |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1394 | __ cfi().RememberState(); |
| 1395 | if (!HasEmptyFrame()) { |
| 1396 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1397 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1398 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1399 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1400 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1401 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1402 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1407 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1408 | __ cfi().AdjustCFAOffset(-adjust); |
| 1409 | |
| 1410 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1411 | Register reg = kCoreCalleeSaves[i]; |
| 1412 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1413 | __ popq(CpuRegister(reg)); |
| 1414 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1415 | __ cfi().Restore(DWARFReg(reg)); |
| 1416 | } |
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1417 | } |
| 1418 | } |
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1419 | __ ret(); |
| 1420 | __ cfi().RestoreState(); |
| 1421 | __ cfi().DefCFAOffset(GetFrameSize()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1422 | } |
| 1423 | |
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1424 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1425 | __ Bind(GetLabelOf(block)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1426 | } |
| 1427 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1428 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1429 | if (source.Equals(destination)) { |
| 1430 | return; |
| 1431 | } |
| 1432 | if (destination.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1433 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1434 | if (source.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1435 | __ movq(dest, source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1436 | } else if (source.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1437 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1438 | } else if (source.IsStackSlot()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1439 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1440 | } else if (source.IsConstant()) { |
| 1441 | HConstant* constant = source.GetConstant(); |
| 1442 | if (constant->IsLongConstant()) { |
| 1443 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1444 | } else { |
| 1445 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1446 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1447 | } else { |
| 1448 | DCHECK(source.IsDoubleStackSlot()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1449 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1450 | } |
| 1451 | } else if (destination.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1452 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1453 | if (source.IsRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1454 | __ movd(dest, source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1455 | } else if (source.IsFpuRegister()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1456 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1457 | } else if (source.IsConstant()) { |
| 1458 | HConstant* constant = source.GetConstant(); |
| 1459 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1460 | if (constant->IsFloatConstant()) { |
| 1461 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1462 | } else { |
| 1463 | Load64BitValue(dest, value); |
| 1464 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1465 | } else if (source.IsStackSlot()) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1466 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1467 | } else { |
| 1468 | DCHECK(source.IsDoubleStackSlot()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1469 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1470 | } |
| 1471 | } else if (destination.IsStackSlot()) { |
| 1472 | if (source.IsRegister()) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1473 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1474 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1475 | } else if (source.IsFpuRegister()) { |
| 1476 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1477 | source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1478 | } else if (source.IsConstant()) { |
| 1479 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1480 | int32_t value = GetInt32ValueOf(constant); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1481 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1482 | } else { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1483 | DCHECK(source.IsStackSlot()) << source; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1484 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1485 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1486 | } |
| 1487 | } else { |
| 1488 | DCHECK(destination.IsDoubleStackSlot()); |
| 1489 | if (source.IsRegister()) { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1490 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1491 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1492 | } else if (source.IsFpuRegister()) { |
| 1493 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1494 | source.AsFpuRegister<XmmRegister>()); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1495 | } else if (source.IsConstant()) { |
| 1496 | HConstant* constant = source.GetConstant(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1497 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1498 | int64_t value = GetInt64ValueOf(constant); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1499 | Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1500 | } else { |
| 1501 | DCHECK(source.IsDoubleStackSlot()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1502 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1503 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1508 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1509 | DCHECK(location.IsRegister()); |
| 1510 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1511 | } |
| 1512 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1513 | void CodeGeneratorX86_64::MoveLocation( |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1514 | Location dst, Location src, DataType::Type dst_type ATTRIBUTE_UNUSED) { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1515 | Move(dst, src); |
| 1516 | } |
| 1517 | |
| 1518 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1519 | if (location.IsRegister()) { |
| 1520 | locations->AddTemp(location); |
| 1521 | } else { |
| 1522 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1523 | } |
| 1524 | } |
| 1525 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1526 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1527 | if (successor->IsExitBlock()) { |
| 1528 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 1529 | return; // no code needed |
| 1530 | } |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1531 | |
| 1532 | HBasicBlock* block = got->GetBlock(); |
| 1533 | HInstruction* previous = got->GetPrevious(); |
| 1534 | |
| 1535 | HLoopInformation* info = block->GetLoopInformation(); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1536 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1537 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 1538 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), 0)); |
| 1539 | __ addw(Address(CpuRegister(TMP), ArtMethod::HotnessCountOffset().Int32Value()), |
| 1540 | Immediate(1)); |
| 1541 | } |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1542 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1543 | return; |
| 1544 | } |
| 1545 | |
| 1546 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1547 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1548 | } |
| 1549 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1550 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1551 | } |
| 1552 | } |
| 1553 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1554 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1555 | got->SetLocations(nullptr); |
| 1556 | } |
| 1557 | |
| 1558 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1559 | HandleGoto(got, got->GetSuccessor()); |
| 1560 | } |
| 1561 | |
| 1562 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1563 | try_boundary->SetLocations(nullptr); |
| 1564 | } |
| 1565 | |
| 1566 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1567 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1568 | if (!successor->IsExitBlock()) { |
| 1569 | HandleGoto(try_boundary, successor); |
| 1570 | } |
| 1571 | } |
| 1572 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1573 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1574 | exit->SetLocations(nullptr); |
| 1575 | } |
| 1576 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1577 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1578 | } |
| 1579 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1580 | template<class LabelType> |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1581 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1582 | LabelType* true_label, |
| 1583 | LabelType* false_label) { |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1584 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1585 | __ j(kUnordered, true_label); |
| 1586 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1587 | __ j(kUnordered, false_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1588 | } |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1589 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1590 | } |
| 1591 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1592 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1593 | LocationSummary* locations = condition->GetLocations(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1594 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1595 | Location left = locations->InAt(0); |
| 1596 | Location right = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1597 | DataType::Type type = condition->InputAt(0)->GetType(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1598 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1599 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1600 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1601 | case DataType::Type::kInt8: |
| 1602 | case DataType::Type::kUint16: |
| 1603 | case DataType::Type::kInt16: |
| 1604 | case DataType::Type::kInt32: |
| 1605 | case DataType::Type::kReference: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1606 | codegen_->GenerateIntCompare(left, right); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1607 | break; |
| 1608 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1609 | case DataType::Type::kInt64: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1610 | codegen_->GenerateLongCompare(left, right); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1611 | break; |
| 1612 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1613 | case DataType::Type::kFloat32: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1614 | if (right.IsFpuRegister()) { |
| 1615 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1616 | } else if (right.IsConstant()) { |
| 1617 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1618 | codegen_->LiteralFloatAddress( |
| 1619 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1620 | } else { |
| 1621 | DCHECK(right.IsStackSlot()); |
| 1622 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1623 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1624 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1625 | break; |
| 1626 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1627 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1628 | if (right.IsFpuRegister()) { |
| 1629 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1630 | } else if (right.IsConstant()) { |
| 1631 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1632 | codegen_->LiteralDoubleAddress( |
| 1633 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1634 | } else { |
| 1635 | DCHECK(right.IsDoubleStackSlot()); |
| 1636 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1637 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1638 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1639 | break; |
| 1640 | } |
| 1641 | default: |
| 1642 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | template<class LabelType> |
| 1647 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1648 | LabelType* true_target_in, |
| 1649 | LabelType* false_target_in) { |
| 1650 | // Generated branching requires both targets to be explicit. If either of the |
| 1651 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1652 | LabelType fallthrough_target; |
| 1653 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1654 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1655 | |
| 1656 | // Generate the comparison to set the CC. |
| 1657 | GenerateCompareTest(condition); |
| 1658 | |
| 1659 | // Now generate the correct jump(s). |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1660 | DataType::Type type = condition->InputAt(0)->GetType(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1661 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1662 | case DataType::Type::kInt64: { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1663 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1664 | break; |
| 1665 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1666 | case DataType::Type::kFloat32: { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1667 | GenerateFPJumps(condition, true_target, false_target); |
| 1668 | break; |
| 1669 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1670 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1671 | GenerateFPJumps(condition, true_target, false_target); |
| 1672 | break; |
| 1673 | } |
| 1674 | default: |
| 1675 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1676 | } |
| 1677 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1678 | if (false_target != &fallthrough_target) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1679 | __ jmp(false_target); |
| 1680 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1681 | |
| 1682 | if (fallthrough_target.IsLinked()) { |
| 1683 | __ Bind(&fallthrough_target); |
| 1684 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1685 | } |
| 1686 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1687 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1688 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1689 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1690 | // conditions if they are materialized due to the complex branching. |
| 1691 | return cond->IsCondition() && |
| 1692 | cond->GetNext() == branch && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1693 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1696 | template<class LabelType> |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1697 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1698 | size_t condition_input_index, |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1699 | LabelType* true_target, |
| 1700 | LabelType* false_target) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1701 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1702 | |
| 1703 | if (true_target == nullptr && false_target == nullptr) { |
| 1704 | // Nothing to do. The code always falls through. |
| 1705 | return; |
| 1706 | } else if (cond->IsIntConstant()) { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1707 | // Constant condition, statically compared against "true" (integer value 1). |
| 1708 | if (cond->AsIntConstant()->IsTrue()) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1709 | if (true_target != nullptr) { |
| 1710 | __ jmp(true_target); |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1711 | } |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1712 | } else { |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1713 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1714 | if (false_target != nullptr) { |
| 1715 | __ jmp(false_target); |
| 1716 | } |
| 1717 | } |
| 1718 | return; |
| 1719 | } |
| 1720 | |
| 1721 | // The following code generates these patterns: |
| 1722 | // (1) true_target == nullptr && false_target != nullptr |
| 1723 | // - opposite condition true => branch to false_target |
| 1724 | // (2) true_target != nullptr && false_target == nullptr |
| 1725 | // - condition true => branch to true_target |
| 1726 | // (3) true_target != nullptr && false_target != nullptr |
| 1727 | // - condition true => branch to true_target |
| 1728 | // - branch to false_target |
| 1729 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1730 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1731 | if (true_target == nullptr) { |
| 1732 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1733 | } else { |
| 1734 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1735 | } |
| 1736 | } else { |
| 1737 | // Materialized condition, compare against 0. |
| 1738 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1739 | if (lhs.IsRegister()) { |
| 1740 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1741 | } else { |
| 1742 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1743 | } |
| 1744 | if (true_target == nullptr) { |
| 1745 | __ j(kEqual, false_target); |
| 1746 | } else { |
| 1747 | __ j(kNotEqual, true_target); |
| 1748 | } |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1749 | } |
| 1750 | } else { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1751 | // Condition has not been materialized, use its inputs as the |
| 1752 | // comparison and its condition as the branch condition. |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1753 | HCondition* condition = cond->AsCondition(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1754 | |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1755 | // If this is a long or FP comparison that has been folded into |
| 1756 | // the HCondition, generate the comparison directly. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1757 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 1758 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1759 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1760 | return; |
| 1761 | } |
| 1762 | |
| 1763 | Location lhs = condition->GetLocations()->InAt(0); |
| 1764 | Location rhs = condition->GetLocations()->InAt(1); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1765 | codegen_->GenerateIntCompare(lhs, rhs); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1766 | if (true_target == nullptr) { |
| 1767 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1768 | } else { |
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1769 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1770 | } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1771 | } |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1772 | |
| 1773 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1774 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1775 | if (true_target != nullptr && false_target != nullptr) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1776 | __ jmp(false_target); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1777 | } |
| 1778 | } |
| 1779 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1780 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1781 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1782 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1783 | locations->SetInAt(0, Location::Any()); |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1788 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1789 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1790 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1791 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1792 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1793 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1794 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1798 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1799 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1800 | InvokeRuntimeCallingConvention calling_convention; |
| 1801 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 1802 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1803 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1804 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1805 | locations->SetInAt(0, Location::Any()); |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1810 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1811 | GenerateTestAndBranch<Label>(deoptimize, |
| 1812 | /* condition_input_index */ 0, |
| 1813 | slow_path->GetEntryLabel(), |
| 1814 | /* false_target */ nullptr); |
| 1815 | } |
| 1816 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1817 | void LocationsBuilderX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1818 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1819 | LocationSummary(flag, LocationSummary::kNoCall); |
| 1820 | locations->SetOut(Location::RequiresRegister()); |
| 1821 | } |
| 1822 | |
| 1823 | void InstructionCodeGeneratorX86_64::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 1824 | __ movl(flag->GetLocations()->Out().AsRegister<CpuRegister>(), |
| 1825 | Address(CpuRegister(RSP), codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); |
| 1826 | } |
| 1827 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1828 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1829 | // There are no conditional move instructions for XMMs. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1830 | if (DataType::IsFloatingPointType(select->GetType())) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1831 | return false; |
| 1832 | } |
| 1833 | |
| 1834 | // A FP condition doesn't generate the single CC that we need. |
| 1835 | HInstruction* condition = select->GetCondition(); |
| 1836 | if (condition->IsCondition() && |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1837 | DataType::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1838 | return false; |
| 1839 | } |
| 1840 | |
| 1841 | // We can generate a CMOV for this Select. |
| 1842 | return true; |
| 1843 | } |
| 1844 | |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1845 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1846 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1847 | if (DataType::IsFloatingPointType(select->GetType())) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1848 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1849 | locations->SetInAt(1, Location::Any()); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1850 | } else { |
| 1851 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1852 | if (SelectCanUseCMOV(select)) { |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1853 | if (select->InputAt(1)->IsConstant()) { |
| 1854 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1855 | } else { |
| 1856 | locations->SetInAt(1, Location::Any()); |
| 1857 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1858 | } else { |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1859 | locations->SetInAt(1, Location::Any()); |
| 1860 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1861 | } |
| 1862 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1863 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1864 | } |
| 1865 | locations->SetOut(Location::SameAsFirstInput()); |
| 1866 | } |
| 1867 | |
| 1868 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1869 | LocationSummary* locations = select->GetLocations(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1870 | if (SelectCanUseCMOV(select)) { |
| 1871 | // If both the condition and the source types are integer, we can generate |
| 1872 | // a CMOV to implement Select. |
| 1873 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1874 | Location value_true_loc = locations->InAt(1); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1875 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1876 | |
| 1877 | HInstruction* select_condition = select->GetCondition(); |
| 1878 | Condition cond = kNotEqual; |
| 1879 | |
| 1880 | // Figure out how to test the 'condition'. |
| 1881 | if (select_condition->IsCondition()) { |
| 1882 | HCondition* condition = select_condition->AsCondition(); |
| 1883 | if (!condition->IsEmittedAtUseSite()) { |
| 1884 | // This was a previously materialized condition. |
| 1885 | // Can we use the existing condition code? |
| 1886 | if (AreEflagsSetFrom(condition, select)) { |
| 1887 | // Materialization was the previous instruction. Condition codes are right. |
| 1888 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1889 | } else { |
| 1890 | // No, we have to recreate the condition code. |
| 1891 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1892 | __ testl(cond_reg, cond_reg); |
| 1893 | } |
| 1894 | } else { |
| 1895 | GenerateCompareTest(condition); |
| 1896 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1897 | } |
| 1898 | } else { |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1899 | // Must be a Boolean condition, which needs to be compared to 0. |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1900 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1901 | __ testl(cond_reg, cond_reg); |
| 1902 | } |
| 1903 | |
| 1904 | // If the condition is true, overwrite the output, which already contains false. |
| 1905 | // Generate the correct sized CMOV. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1906 | bool is_64_bit = DataType::Is64BitType(select->GetType()); |
| Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1907 | if (value_true_loc.IsRegister()) { |
| 1908 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1909 | } else { |
| 1910 | __ cmov(cond, |
| 1911 | value_false, |
| 1912 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1913 | } |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1914 | } else { |
| 1915 | NearLabel false_target; |
| 1916 | GenerateTestAndBranch<NearLabel>(select, |
| 1917 | /* condition_input_index */ 2, |
| 1918 | /* true_target */ nullptr, |
| 1919 | &false_target); |
| 1920 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1921 | __ Bind(&false_target); |
| 1922 | } |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1925 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1926 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1929 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1930 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | void CodeGeneratorX86_64::GenerateNop() { |
| 1934 | __ nop(); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1935 | } |
| 1936 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1937 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1938 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1939 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1940 | // Handle the long/FP comparisons made in instruction simplification. |
| 1941 | switch (cond->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1942 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1943 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1944 | locations->SetInAt(1, Location::Any()); |
| 1945 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1946 | case DataType::Type::kFloat32: |
| 1947 | case DataType::Type::kFloat64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1948 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1949 | locations->SetInAt(1, Location::Any()); |
| 1950 | break; |
| 1951 | default: |
| 1952 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1953 | locations->SetInAt(1, Location::Any()); |
| 1954 | break; |
| 1955 | } |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1956 | if (!cond->IsEmittedAtUseSite()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1957 | locations->SetOut(Location::RequiresRegister()); |
| 1958 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1959 | } |
| 1960 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1961 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1962 | if (cond->IsEmittedAtUseSite()) { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1963 | return; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1964 | } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1965 | |
| 1966 | LocationSummary* locations = cond->GetLocations(); |
| 1967 | Location lhs = locations->InAt(0); |
| 1968 | Location rhs = locations->InAt(1); |
| 1969 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1970 | NearLabel true_label, false_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1971 | |
| 1972 | switch (cond->InputAt(0)->GetType()) { |
| 1973 | default: |
| 1974 | // Integer case. |
| 1975 | |
| 1976 | // Clear output register: setcc only sets the low byte. |
| 1977 | __ xorl(reg, reg); |
| 1978 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1979 | codegen_->GenerateIntCompare(lhs, rhs); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1980 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1981 | return; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1982 | case DataType::Type::kInt64: |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1983 | // Clear output register: setcc only sets the low byte. |
| 1984 | __ xorl(reg, reg); |
| 1985 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1986 | codegen_->GenerateLongCompare(lhs, rhs); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1987 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1988 | return; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1989 | case DataType::Type::kFloat32: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1990 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1991 | if (rhs.IsConstant()) { |
| 1992 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1993 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1994 | } else if (rhs.IsStackSlot()) { |
| 1995 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1996 | } else { |
| 1997 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1998 | } |
| 1999 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2000 | break; |
| 2001 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2002 | case DataType::Type::kFloat64: { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2003 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 2004 | if (rhs.IsConstant()) { |
| 2005 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2006 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 2007 | } else if (rhs.IsDoubleStackSlot()) { |
| 2008 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 2009 | } else { |
| 2010 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 2011 | } |
| 2012 | GenerateFPJumps(cond, &true_label, &false_label); |
| 2013 | break; |
| 2014 | } |
| 2015 | } |
| 2016 | |
| 2017 | // Convert the jumps into the result. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2018 | NearLabel done_label; |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2019 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2020 | // False case: result = 0. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2021 | __ Bind(&false_label); |
| 2022 | __ xorl(reg, reg); |
| 2023 | __ jmp(&done_label); |
| 2024 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2025 | // True case: result = 1. |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2026 | __ Bind(&true_label); |
| 2027 | __ movl(reg, Immediate(1)); |
| 2028 | __ Bind(&done_label); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2032 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2036 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2040 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2044 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2048 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2052 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2056 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2060 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2064 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2068 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2072 | HandleCondition(comp); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2076 | HandleCondition(comp); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2077 | } |
| 2078 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2079 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2080 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2084 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2088 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2092 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2096 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2100 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2104 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2108 | HandleCondition(comp); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2111 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2112 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2113 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2114 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2115 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2116 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2117 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2118 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2119 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2120 | case DataType::Type::kInt32: |
| 2121 | case DataType::Type::kInt64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2122 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2123 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2124 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2125 | break; |
| 2126 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2127 | case DataType::Type::kFloat32: |
| 2128 | case DataType::Type::kFloat64: { |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2129 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2130 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2131 | locations->SetOut(Location::RequiresRegister()); |
| 2132 | break; |
| 2133 | } |
| 2134 | default: |
| 2135 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 2136 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2140 | LocationSummary* locations = compare->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2141 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2142 | Location left = locations->InAt(0); |
| 2143 | Location right = locations->InAt(1); |
| 2144 | |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2145 | NearLabel less, greater, done; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2146 | DataType::Type type = compare->InputAt(0)->GetType(); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2147 | Condition less_cond = kLess; |
| 2148 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2149 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2150 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2151 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2152 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2153 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2154 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2155 | case DataType::Type::kInt32: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2156 | codegen_->GenerateIntCompare(left, right); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2157 | break; |
| 2158 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2159 | case DataType::Type::kInt64: { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 2160 | codegen_->GenerateLongCompare(left, right); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2161 | break; |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2162 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2163 | case DataType::Type::kFloat32: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2164 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2165 | if (right.IsConstant()) { |
| 2166 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2167 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2168 | } else if (right.IsStackSlot()) { |
| 2169 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2170 | } else { |
| 2171 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2172 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2173 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2174 | less_cond = kBelow; // ucomis{s,d} sets CF |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2175 | break; |
| 2176 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2177 | case DataType::Type::kFloat64: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2178 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2179 | if (right.IsConstant()) { |
| 2180 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2181 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2182 | } else if (right.IsDoubleStackSlot()) { |
| 2183 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2184 | } else { |
| 2185 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2186 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2187 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2188 | less_cond = kBelow; // ucomis{s,d} sets CF |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2189 | break; |
| 2190 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2191 | default: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2192 | LOG(FATAL) << "Unexpected compare type " << type; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2193 | } |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2194 | |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2195 | __ movl(out, Immediate(0)); |
| Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2196 | __ j(kEqual, &done); |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2197 | __ j(less_cond, &less); |
| Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2198 | |
| Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2199 | __ Bind(&greater); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2200 | __ movl(out, Immediate(1)); |
| 2201 | __ jmp(&done); |
| 2202 | |
| 2203 | __ Bind(&less); |
| 2204 | __ movl(out, Immediate(-1)); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2205 | |
| 2206 | __ Bind(&done); |
| 2207 | } |
| 2208 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2209 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2210 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2211 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2212 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2213 | } |
| 2214 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2215 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2216 | // Will be generated at use site. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2217 | } |
| 2218 | |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2219 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2220 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2221 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2222 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2223 | } |
| 2224 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2225 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2226 | // Will be generated at use site. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2229 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2230 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2231 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2232 | locations->SetOut(Location::ConstantLocation(constant)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2233 | } |
| 2234 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2235 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2236 | // Will be generated at use site. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2237 | } |
| 2238 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2239 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2240 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2241 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2242 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2243 | } |
| 2244 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2245 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2246 | // Will be generated at use site. |
| 2247 | } |
| 2248 | |
| 2249 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2250 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2251 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2252 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2253 | } |
| 2254 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2255 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2256 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2257 | // Will be generated at use site. |
| 2258 | } |
| 2259 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2260 | void LocationsBuilderX86_64::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 2261 | constructor_fence->SetLocations(nullptr); |
| 2262 | } |
| 2263 | |
| 2264 | void InstructionCodeGeneratorX86_64::VisitConstructorFence( |
| 2265 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 2266 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 2267 | } |
| 2268 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2269 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2270 | memory_barrier->SetLocations(nullptr); |
| 2271 | } |
| 2272 | |
| 2273 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2274 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2275 | } |
| 2276 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2277 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2278 | ret->SetLocations(nullptr); |
| 2279 | } |
| 2280 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2281 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2282 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2286 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2287 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2288 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2289 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2290 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2291 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2292 | case DataType::Type::kInt8: |
| 2293 | case DataType::Type::kUint16: |
| 2294 | case DataType::Type::kInt16: |
| 2295 | case DataType::Type::kInt32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2296 | case DataType::Type::kInt64: |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2297 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2298 | break; |
| 2299 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2300 | case DataType::Type::kFloat32: |
| 2301 | case DataType::Type::kFloat64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2302 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2303 | break; |
| 2304 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2305 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2306 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2307 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2311 | if (kIsDebugBuild) { |
| 2312 | switch (ret->InputAt(0)->GetType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2313 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2314 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2315 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2316 | case DataType::Type::kInt8: |
| 2317 | case DataType::Type::kUint16: |
| 2318 | case DataType::Type::kInt16: |
| 2319 | case DataType::Type::kInt32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2320 | case DataType::Type::kInt64: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2321 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2322 | break; |
| 2323 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2324 | case DataType::Type::kFloat32: |
| 2325 | case DataType::Type::kFloat64: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2326 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2327 | XMM0); |
| 2328 | break; |
| 2329 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2330 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2331 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | codegen_->GenerateFrameExit(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2335 | } |
| 2336 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2337 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(DataType::Type type) const { |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2338 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2339 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2340 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2341 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2342 | case DataType::Type::kInt8: |
| 2343 | case DataType::Type::kUint16: |
| 2344 | case DataType::Type::kInt16: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2345 | case DataType::Type::kUint32: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2346 | case DataType::Type::kInt32: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2347 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2348 | case DataType::Type::kInt64: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2349 | return Location::RegisterLocation(RAX); |
| 2350 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2351 | case DataType::Type::kVoid: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2352 | return Location::NoLocation(); |
| 2353 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2354 | case DataType::Type::kFloat64: |
| 2355 | case DataType::Type::kFloat32: |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2356 | return Location::FpuRegisterLocation(XMM0); |
| 2357 | } |
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2358 | |
| 2359 | UNREACHABLE(); |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2363 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2364 | } |
| 2365 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2366 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(DataType::Type type) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2367 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2368 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2369 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2370 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2371 | case DataType::Type::kInt8: |
| 2372 | case DataType::Type::kUint16: |
| 2373 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2374 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2375 | uint32_t index = gp_index_++; |
| 2376 | stack_index_++; |
| 2377 | if (index < calling_convention.GetNumberOfRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2378 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2379 | } else { |
| 2380 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2381 | } |
| 2382 | } |
| 2383 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2384 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2385 | uint32_t index = gp_index_; |
| 2386 | stack_index_ += 2; |
| 2387 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2388 | gp_index_ += 1; |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2389 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2390 | } else { |
| 2391 | gp_index_ += 2; |
| 2392 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2393 | } |
| 2394 | } |
| 2395 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2396 | case DataType::Type::kFloat32: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2397 | uint32_t index = float_index_++; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2398 | stack_index_++; |
| 2399 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2400 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2401 | } else { |
| 2402 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2403 | } |
| 2404 | } |
| 2405 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2406 | case DataType::Type::kFloat64: { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2407 | uint32_t index = float_index_++; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2408 | stack_index_ += 2; |
| 2409 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2410 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2411 | } else { |
| 2412 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2413 | } |
| 2414 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2415 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2416 | case DataType::Type::kUint32: |
| 2417 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2418 | case DataType::Type::kVoid: |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2419 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2420 | break; |
| 2421 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2422 | return Location::NoLocation(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2423 | } |
| 2424 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2425 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2426 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2427 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2428 | // the method_idx. |
| 2429 | HandleInvoke(invoke); |
| 2430 | } |
| 2431 | |
| 2432 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2433 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2434 | } |
| 2435 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2436 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2437 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2438 | // art::PrepareForRegisterAllocation. |
| 2439 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2440 | |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2441 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2442 | if (intrinsic.TryDispatch(invoke)) { |
| 2443 | return; |
| 2444 | } |
| 2445 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2446 | HandleInvoke(invoke); |
| 2447 | } |
| 2448 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2449 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2450 | if (invoke->GetLocations()->Intrinsified()) { |
| 2451 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2452 | intrinsic.Dispatch(invoke); |
| 2453 | return true; |
| 2454 | } |
| 2455 | return false; |
| 2456 | } |
| 2457 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2458 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2459 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2460 | // art::PrepareForRegisterAllocation. |
| 2461 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2462 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2463 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2464 | return; |
| 2465 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2466 | |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2467 | LocationSummary* locations = invoke->GetLocations(); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2468 | codegen_->GenerateStaticOrDirectCall( |
| Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2469 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2470 | } |
| 2471 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2472 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2473 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2474 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2475 | } |
| 2476 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2477 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2478 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2479 | if (intrinsic.TryDispatch(invoke)) { |
| 2480 | return; |
| 2481 | } |
| 2482 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2483 | HandleInvoke(invoke); |
| 2484 | } |
| 2485 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2486 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2487 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2488 | return; |
| 2489 | } |
| 2490 | |
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2491 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2492 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2493 | } |
| 2494 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2495 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2496 | HandleInvoke(invoke); |
| 2497 | // Add the hidden argument. |
| 2498 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2499 | } |
| 2500 | |
| 2501 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2502 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2503 | LocationSummary* locations = invoke->GetLocations(); |
| 2504 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2505 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2506 | Location receiver = locations->InAt(0); |
| 2507 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2508 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2509 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2510 | // won't be modified thereafter, before the `call` instruction. |
| 2511 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2512 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2513 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2514 | if (receiver.IsStackSlot()) { |
| 2515 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2516 | // /* HeapReference<Class> */ temp = temp->klass_ |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2517 | __ movl(temp, Address(temp, class_offset)); |
| 2518 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2519 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2520 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2521 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2522 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2523 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2524 | // emit a read barrier for the previous class reference load. |
| 2525 | // However this is not required in practice, as this is an |
| 2526 | // intermediate/temporary reference and because the current |
| 2527 | // concurrent copying collector keeps the from-space memory |
| 2528 | // intact/accessible until the end of the marking phase (the |
| 2529 | // concurrent copying collector may not in the future). |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2530 | __ MaybeUnpoisonHeapReference(temp); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2531 | // temp = temp->GetAddressOfIMT() |
| 2532 | __ movq(temp, |
| 2533 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2534 | // temp = temp->GetImtEntryAt(method_offset); |
| 2535 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2536 | invoke->GetImtIndex(), kX86_64PointerSize)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2537 | // temp = temp->GetImtEntryAt(method_offset); |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2538 | __ movq(temp, Address(temp, method_offset)); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2539 | // call temp->GetEntryPoint(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2540 | __ call(Address( |
| 2541 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2542 | |
| 2543 | DCHECK(!codegen_->IsLeafMethod()); |
| 2544 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2545 | } |
| 2546 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2547 | void LocationsBuilderX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2548 | HandleInvoke(invoke); |
| 2549 | } |
| 2550 | |
| 2551 | void InstructionCodeGeneratorX86_64::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 2552 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| 2553 | } |
| 2554 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2555 | void LocationsBuilderX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2556 | HandleInvoke(invoke); |
| 2557 | } |
| 2558 | |
| 2559 | void InstructionCodeGeneratorX86_64::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 2560 | codegen_->GenerateInvokeCustomCall(invoke); |
| 2561 | } |
| 2562 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2563 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2564 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2565 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2566 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2567 | case DataType::Type::kInt32: |
| 2568 | case DataType::Type::kInt64: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2569 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2570 | locations->SetOut(Location::SameAsFirstInput()); |
| 2571 | break; |
| 2572 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2573 | case DataType::Type::kFloat32: |
| 2574 | case DataType::Type::kFloat64: |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2575 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2576 | locations->SetOut(Location::SameAsFirstInput()); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2577 | locations->AddTemp(Location::RequiresFpuRegister()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2578 | break; |
| 2579 | |
| 2580 | default: |
| 2581 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2586 | LocationSummary* locations = neg->GetLocations(); |
| 2587 | Location out = locations->Out(); |
| 2588 | Location in = locations->InAt(0); |
| 2589 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2590 | case DataType::Type::kInt32: |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2591 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2592 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2593 | __ negl(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2594 | break; |
| 2595 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2596 | case DataType::Type::kInt64: |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2597 | DCHECK(in.IsRegister()); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2598 | DCHECK(in.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2599 | __ negq(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2600 | break; |
| 2601 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2602 | case DataType::Type::kFloat32: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2603 | DCHECK(in.Equals(out)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2604 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2605 | // Implement float negation with an exclusive or with value |
| 2606 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2607 | // single-precision floating-point number). |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2608 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2609 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2610 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2611 | } |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2612 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2613 | case DataType::Type::kFloat64: { |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2614 | DCHECK(in.Equals(out)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2615 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2616 | // Implement double negation with an exclusive or with value |
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2617 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2618 | // a double-precision floating-point number). |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2619 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2620 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2621 | break; |
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2622 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2623 | |
| 2624 | default: |
| 2625 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2626 | } |
| 2627 | } |
| 2628 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2629 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2630 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2631 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2632 | DataType::Type result_type = conversion->GetResultType(); |
| 2633 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2634 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2635 | << input_type << " -> " << result_type; |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2636 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2637 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2638 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2639 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2640 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2641 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2642 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 2643 | locations->SetInAt(0, Location::Any()); |
| 2644 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2645 | break; |
| 2646 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2647 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2648 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2649 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2650 | locations->SetInAt(0, Location::Any()); |
| 2651 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2652 | break; |
| 2653 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2654 | case DataType::Type::kFloat32: |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2655 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2656 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2657 | break; |
| 2658 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2659 | case DataType::Type::kFloat64: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2660 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2661 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2662 | break; |
| 2663 | |
| 2664 | default: |
| 2665 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2666 | << " to " << result_type; |
| 2667 | } |
| 2668 | break; |
| 2669 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2670 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2671 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2672 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2673 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2674 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2675 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2676 | case DataType::Type::kInt16: |
| 2677 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2678 | // TODO: We would benefit from a (to-be-implemented) |
| 2679 | // Location::RegisterOrStackSlot requirement for this input. |
| 2680 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2681 | locations->SetOut(Location::RequiresRegister()); |
| 2682 | break; |
| 2683 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2684 | case DataType::Type::kFloat32: |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2685 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2686 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2687 | break; |
| 2688 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2689 | case DataType::Type::kFloat64: |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2690 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2691 | locations->SetOut(Location::RequiresRegister()); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2692 | break; |
| 2693 | |
| 2694 | default: |
| 2695 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2696 | << " to " << result_type; |
| 2697 | } |
| 2698 | break; |
| 2699 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2700 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2701 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2702 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2703 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2704 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2705 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2706 | case DataType::Type::kInt16: |
| 2707 | case DataType::Type::kInt32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2708 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2709 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2710 | break; |
| 2711 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2712 | case DataType::Type::kInt64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2713 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2714 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2715 | break; |
| 2716 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2717 | case DataType::Type::kFloat64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2718 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2719 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2720 | break; |
| 2721 | |
| 2722 | default: |
| 2723 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2724 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2725 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2726 | break; |
| 2727 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2728 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2729 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2730 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2731 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2732 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2733 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2734 | case DataType::Type::kInt16: |
| 2735 | case DataType::Type::kInt32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2736 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2737 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2738 | break; |
| 2739 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2740 | case DataType::Type::kInt64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2741 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2742 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2743 | break; |
| 2744 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2745 | case DataType::Type::kFloat32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2746 | locations->SetInAt(0, Location::Any()); |
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2747 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2748 | break; |
| 2749 | |
| 2750 | default: |
| 2751 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2752 | << " to " << result_type; |
| 2753 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2754 | break; |
| 2755 | |
| 2756 | default: |
| 2757 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2758 | << " to " << result_type; |
| 2759 | } |
| 2760 | } |
| 2761 | |
| 2762 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2763 | LocationSummary* locations = conversion->GetLocations(); |
| 2764 | Location out = locations->Out(); |
| 2765 | Location in = locations->InAt(0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2766 | DataType::Type result_type = conversion->GetResultType(); |
| 2767 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2768 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 2769 | << input_type << " -> " << result_type; |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2770 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2771 | case DataType::Type::kUint8: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2772 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2773 | case DataType::Type::kInt8: |
| 2774 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2775 | case DataType::Type::kInt16: |
| 2776 | case DataType::Type::kInt32: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2777 | case DataType::Type::kInt64: |
| 2778 | if (in.IsRegister()) { |
| 2779 | __ movzxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 2780 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 2781 | __ movzxb(out.AsRegister<CpuRegister>(), |
| 2782 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2783 | } else { |
| 2784 | __ movl(out.AsRegister<CpuRegister>(), |
| 2785 | Immediate(static_cast<uint8_t>(Int64FromConstant(in.GetConstant())))); |
| 2786 | } |
| 2787 | break; |
| 2788 | |
| 2789 | default: |
| 2790 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2791 | << " to " << result_type; |
| 2792 | } |
| 2793 | break; |
| 2794 | |
| 2795 | case DataType::Type::kInt8: |
| 2796 | switch (input_type) { |
| 2797 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2798 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2799 | case DataType::Type::kInt16: |
| 2800 | case DataType::Type::kInt32: |
| 2801 | case DataType::Type::kInt64: |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2802 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2803 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2804 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2805 | __ movsxb(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2806 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2807 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2808 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2809 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2810 | } |
| 2811 | break; |
| 2812 | |
| 2813 | default: |
| 2814 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2815 | << " to " << result_type; |
| 2816 | } |
| 2817 | break; |
| 2818 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2819 | case DataType::Type::kUint16: |
| 2820 | switch (input_type) { |
| 2821 | case DataType::Type::kInt8: |
| 2822 | case DataType::Type::kInt16: |
| 2823 | case DataType::Type::kInt32: |
| 2824 | case DataType::Type::kInt64: |
| 2825 | if (in.IsRegister()) { |
| 2826 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| 2827 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| 2828 | __ movzxw(out.AsRegister<CpuRegister>(), |
| 2829 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2830 | } else { |
| 2831 | __ movl(out.AsRegister<CpuRegister>(), |
| 2832 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
| 2833 | } |
| 2834 | break; |
| 2835 | |
| 2836 | default: |
| 2837 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2838 | << " to " << result_type; |
| 2839 | } |
| 2840 | break; |
| 2841 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2842 | case DataType::Type::kInt16: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2843 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2844 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2845 | case DataType::Type::kInt32: |
| 2846 | case DataType::Type::kInt64: |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2847 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2848 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2849 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2850 | __ movsxw(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2851 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2852 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2853 | __ movl(out.AsRegister<CpuRegister>(), |
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2854 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2855 | } |
| 2856 | break; |
| 2857 | |
| 2858 | default: |
| 2859 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2860 | << " to " << result_type; |
| 2861 | } |
| 2862 | break; |
| 2863 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2864 | case DataType::Type::kInt32: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2865 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2866 | case DataType::Type::kInt64: |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2867 | if (in.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2868 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2869 | } else if (in.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2870 | __ movl(out.AsRegister<CpuRegister>(), |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2871 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2872 | } else { |
| 2873 | DCHECK(in.IsConstant()); |
| 2874 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2875 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2876 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2877 | } |
| 2878 | break; |
| 2879 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2880 | case DataType::Type::kFloat32: { |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2881 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2882 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2883 | NearLabel done, nan; |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2884 | |
| 2885 | __ movl(output, Immediate(kPrimIntMax)); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2886 | // if input >= (float)INT_MAX goto done |
| 2887 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2888 | __ j(kAboveEqual, &done); |
| 2889 | // if input == NaN goto nan |
| 2890 | __ j(kUnordered, &nan); |
| 2891 | // output = float-to-int-truncate(input) |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2892 | __ cvttss2si(output, input, false); |
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2893 | __ jmp(&done); |
| 2894 | __ Bind(&nan); |
| 2895 | // output = 0 |
| 2896 | __ xorl(output, output); |
| 2897 | __ Bind(&done); |
| 2898 | break; |
| 2899 | } |
| 2900 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2901 | case DataType::Type::kFloat64: { |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2902 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2903 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2904 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2905 | |
| 2906 | __ movl(output, Immediate(kPrimIntMax)); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2907 | // if input >= (double)INT_MAX goto done |
| 2908 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2909 | __ j(kAboveEqual, &done); |
| 2910 | // if input == NaN goto nan |
| 2911 | __ j(kUnordered, &nan); |
| 2912 | // output = double-to-int-truncate(input) |
| 2913 | __ cvttsd2si(output, input); |
| 2914 | __ jmp(&done); |
| 2915 | __ Bind(&nan); |
| 2916 | // output = 0 |
| 2917 | __ xorl(output, output); |
| 2918 | __ Bind(&done); |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2919 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2920 | } |
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2921 | |
| 2922 | default: |
| 2923 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2924 | << " to " << result_type; |
| 2925 | } |
| 2926 | break; |
| 2927 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2928 | case DataType::Type::kInt64: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2929 | switch (input_type) { |
| 2930 | DCHECK(out.IsRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2931 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2932 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2933 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2934 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2935 | case DataType::Type::kInt16: |
| 2936 | case DataType::Type::kInt32: |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2937 | DCHECK(in.IsRegister()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2938 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2939 | break; |
| 2940 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2941 | case DataType::Type::kFloat32: { |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2942 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2943 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2944 | NearLabel done, nan; |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2945 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2946 | codegen_->Load64BitValue(output, kPrimLongMax); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2947 | // if input >= (float)LONG_MAX goto done |
| 2948 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2949 | __ j(kAboveEqual, &done); |
| 2950 | // if input == NaN goto nan |
| 2951 | __ j(kUnordered, &nan); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2952 | // output = float-to-long-truncate(input) |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2953 | __ cvttss2si(output, input, true); |
| 2954 | __ jmp(&done); |
| 2955 | __ Bind(&nan); |
| 2956 | // output = 0 |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2957 | __ xorl(output, output); |
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2958 | __ Bind(&done); |
| 2959 | break; |
| 2960 | } |
| 2961 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2962 | case DataType::Type::kFloat64: { |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2963 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2964 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2965 | NearLabel done, nan; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2966 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2967 | codegen_->Load64BitValue(output, kPrimLongMax); |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2968 | // if input >= (double)LONG_MAX goto done |
| 2969 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2970 | __ j(kAboveEqual, &done); |
| 2971 | // if input == NaN goto nan |
| 2972 | __ j(kUnordered, &nan); |
| 2973 | // output = double-to-long-truncate(input) |
| 2974 | __ cvttsd2si(output, input, true); |
| 2975 | __ jmp(&done); |
| 2976 | __ Bind(&nan); |
| 2977 | // output = 0 |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2978 | __ xorl(output, output); |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2979 | __ Bind(&done); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2980 | break; |
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2981 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2982 | |
| 2983 | default: |
| 2984 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2985 | << " to " << result_type; |
| 2986 | } |
| 2987 | break; |
| 2988 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2989 | case DataType::Type::kFloat32: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2990 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2991 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2992 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2993 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2994 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2995 | case DataType::Type::kInt16: |
| 2996 | case DataType::Type::kInt32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2997 | if (in.IsRegister()) { |
| 2998 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2999 | } else if (in.IsConstant()) { |
| 3000 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3001 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3002 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3003 | } else { |
| 3004 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3005 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3006 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3007 | break; |
| 3008 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3009 | case DataType::Type::kInt64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3010 | if (in.IsRegister()) { |
| 3011 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3012 | } else if (in.IsConstant()) { |
| 3013 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3014 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 3015 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3016 | } else { |
| 3017 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 3018 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3019 | } |
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 3020 | break; |
| 3021 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3022 | case DataType::Type::kFloat64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3023 | if (in.IsFpuRegister()) { |
| 3024 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3025 | } else if (in.IsConstant()) { |
| 3026 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 3027 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3028 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3029 | } else { |
| 3030 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 3031 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3032 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3033 | break; |
| 3034 | |
| 3035 | default: |
| 3036 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3037 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3038 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3039 | break; |
| 3040 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3041 | case DataType::Type::kFloat64: |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3042 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3043 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3044 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3045 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3046 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3047 | case DataType::Type::kInt16: |
| 3048 | case DataType::Type::kInt32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3049 | if (in.IsRegister()) { |
| 3050 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 3051 | } else if (in.IsConstant()) { |
| 3052 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 3053 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3054 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3055 | } else { |
| 3056 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3057 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 3058 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3059 | break; |
| 3060 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3061 | case DataType::Type::kInt64: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3062 | if (in.IsRegister()) { |
| 3063 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 3064 | } else if (in.IsConstant()) { |
| 3065 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3066 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3067 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3068 | } else { |
| 3069 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 3070 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 3071 | } |
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 3072 | break; |
| 3073 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3074 | case DataType::Type::kFloat32: |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3075 | if (in.IsFpuRegister()) { |
| 3076 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 3077 | } else if (in.IsConstant()) { |
| 3078 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 3079 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 3080 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3081 | } else { |
| 3082 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 3083 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 3084 | } |
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 3085 | break; |
| 3086 | |
| 3087 | default: |
| 3088 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3089 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3090 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3091 | break; |
| 3092 | |
| 3093 | default: |
| 3094 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3095 | << " to " << result_type; |
| 3096 | } |
| 3097 | } |
| 3098 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3099 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3100 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3101 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3102 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3103 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3104 | locations->SetInAt(0, Location::RequiresRegister()); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3105 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3106 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3107 | break; |
| 3108 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3109 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3110 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3111 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3112 | // 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] | 3113 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3114 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3115 | break; |
| 3116 | } |
| 3117 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3118 | case DataType::Type::kFloat64: |
| 3119 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3120 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3121 | locations->SetInAt(1, Location::Any()); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3122 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3123 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3124 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3125 | |
| 3126 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3127 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3128 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3132 | LocationSummary* locations = add->GetLocations(); |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3133 | Location first = locations->InAt(0); |
| 3134 | Location second = locations->InAt(1); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3135 | Location out = locations->Out(); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3136 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3137 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3138 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3139 | if (second.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3140 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3141 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3142 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3143 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3144 | } else { |
| 3145 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3146 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3147 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3148 | } else if (second.IsConstant()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3149 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3150 | __ addl(out.AsRegister<CpuRegister>(), |
| 3151 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3152 | } else { |
| 3153 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3154 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3155 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3156 | } else { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3157 | DCHECK(first.Equals(locations->Out())); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3158 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3159 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3160 | break; |
| 3161 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3162 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3163 | case DataType::Type::kInt64: { |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3164 | if (second.IsRegister()) { |
| 3165 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3166 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3167 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3168 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3169 | } else { |
| 3170 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3171 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3172 | } |
| 3173 | } else { |
| 3174 | DCHECK(second.IsConstant()); |
| 3175 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3176 | int32_t int32_value = Low32Bits(value); |
| 3177 | DCHECK_EQ(int32_value, value); |
| 3178 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3179 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3180 | } else { |
| 3181 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3182 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3183 | } |
| 3184 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3185 | break; |
| 3186 | } |
| 3187 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3188 | case DataType::Type::kFloat32: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3189 | if (second.IsFpuRegister()) { |
| 3190 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3191 | } else if (second.IsConstant()) { |
| 3192 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3193 | codegen_->LiteralFloatAddress( |
| 3194 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3195 | } else { |
| 3196 | DCHECK(second.IsStackSlot()); |
| 3197 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3198 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3199 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3200 | break; |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3201 | } |
| 3202 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3203 | case DataType::Type::kFloat64: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3204 | if (second.IsFpuRegister()) { |
| 3205 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3206 | } else if (second.IsConstant()) { |
| 3207 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3208 | codegen_->LiteralDoubleAddress( |
| 3209 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3210 | } else { |
| 3211 | DCHECK(second.IsDoubleStackSlot()); |
| 3212 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3213 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3214 | } |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3215 | break; |
| 3216 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3217 | |
| 3218 | default: |
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3219 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3224 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3225 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3226 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3227 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3228 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3229 | locations->SetInAt(1, Location::Any()); |
| 3230 | locations->SetOut(Location::SameAsFirstInput()); |
| 3231 | break; |
| 3232 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3233 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3234 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3235 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3236 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3237 | break; |
| 3238 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3239 | case DataType::Type::kFloat32: |
| 3240 | case DataType::Type::kFloat64: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3241 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3242 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3243 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3244 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3245 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3246 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3247 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3248 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3252 | LocationSummary* locations = sub->GetLocations(); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3253 | Location first = locations->InAt(0); |
| 3254 | Location second = locations->InAt(1); |
| 3255 | DCHECK(first.Equals(locations->Out())); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3256 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3257 | case DataType::Type::kInt32: { |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3258 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3259 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3260 | } else if (second.IsConstant()) { |
| 3261 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3262 | __ subl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3263 | } else { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3264 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3265 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3266 | break; |
| 3267 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3268 | case DataType::Type::kInt64: { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3269 | if (second.IsConstant()) { |
| 3270 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3271 | DCHECK(IsInt<32>(value)); |
| 3272 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3273 | } else { |
| 3274 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3275 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3276 | break; |
| 3277 | } |
| 3278 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3279 | case DataType::Type::kFloat32: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3280 | if (second.IsFpuRegister()) { |
| 3281 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3282 | } else if (second.IsConstant()) { |
| 3283 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3284 | codegen_->LiteralFloatAddress( |
| 3285 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3286 | } else { |
| 3287 | DCHECK(second.IsStackSlot()); |
| 3288 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3289 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3290 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3291 | break; |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3292 | } |
| 3293 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3294 | case DataType::Type::kFloat64: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3295 | if (second.IsFpuRegister()) { |
| 3296 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3297 | } else if (second.IsConstant()) { |
| 3298 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3299 | codegen_->LiteralDoubleAddress( |
| 3300 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3301 | } else { |
| 3302 | DCHECK(second.IsDoubleStackSlot()); |
| 3303 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3304 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3305 | } |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3306 | break; |
| 3307 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3308 | |
| 3309 | default: |
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3310 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3311 | } |
| 3312 | } |
| 3313 | |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3314 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3315 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3316 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3317 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3318 | case DataType::Type::kInt32: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3319 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3320 | locations->SetInAt(1, Location::Any()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3321 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3322 | // Can use 3 operand multiply. |
| 3323 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3324 | } else { |
| 3325 | locations->SetOut(Location::SameAsFirstInput()); |
| 3326 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3327 | break; |
| 3328 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3329 | case DataType::Type::kInt64: { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3330 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3331 | locations->SetInAt(1, Location::Any()); |
| 3332 | if (mul->InputAt(1)->IsLongConstant() && |
| 3333 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3334 | // Can use 3 operand multiply. |
| 3335 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3336 | } else { |
| 3337 | locations->SetOut(Location::SameAsFirstInput()); |
| 3338 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3339 | break; |
| 3340 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3341 | case DataType::Type::kFloat32: |
| 3342 | case DataType::Type::kFloat64: { |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3343 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3344 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3345 | locations->SetOut(Location::SameAsFirstInput()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3346 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3347 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3348 | |
| 3349 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3350 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3351 | } |
| 3352 | } |
| 3353 | |
| 3354 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3355 | LocationSummary* locations = mul->GetLocations(); |
| 3356 | Location first = locations->InAt(0); |
| 3357 | Location second = locations->InAt(1); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3358 | Location out = locations->Out(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3359 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3360 | case DataType::Type::kInt32: |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3361 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3362 | // problems where the output may not be the same as the first operand. |
| 3363 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3364 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3365 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3366 | } else if (second.IsRegister()) { |
| 3367 | DCHECK(first.Equals(out)); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3368 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3369 | } else { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3370 | DCHECK(first.Equals(out)); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3371 | DCHECK(second.IsStackSlot()); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3372 | __ imull(first.AsRegister<CpuRegister>(), |
| 3373 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3374 | } |
| 3375 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3376 | case DataType::Type::kInt64: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3377 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3378 | // problems where the output may not be the same as the first operand. |
| 3379 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3380 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3381 | if (IsInt<32>(value)) { |
| 3382 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3383 | Immediate(static_cast<int32_t>(value))); |
| 3384 | } else { |
| 3385 | // Have to use the constant area. |
| 3386 | DCHECK(first.Equals(out)); |
| 3387 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3388 | } |
| 3389 | } else if (second.IsRegister()) { |
| 3390 | DCHECK(first.Equals(out)); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3391 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3392 | } else { |
| 3393 | DCHECK(second.IsDoubleStackSlot()); |
| 3394 | DCHECK(first.Equals(out)); |
| 3395 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3396 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3397 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3398 | break; |
| 3399 | } |
| 3400 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3401 | case DataType::Type::kFloat32: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3402 | DCHECK(first.Equals(out)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3403 | if (second.IsFpuRegister()) { |
| 3404 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3405 | } else if (second.IsConstant()) { |
| 3406 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3407 | codegen_->LiteralFloatAddress( |
| 3408 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3409 | } else { |
| 3410 | DCHECK(second.IsStackSlot()); |
| 3411 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3412 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3413 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3414 | break; |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3415 | } |
| 3416 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3417 | case DataType::Type::kFloat64: { |
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3418 | DCHECK(first.Equals(out)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3419 | if (second.IsFpuRegister()) { |
| 3420 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3421 | } else if (second.IsConstant()) { |
| 3422 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3423 | codegen_->LiteralDoubleAddress( |
| 3424 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3425 | } else { |
| 3426 | DCHECK(second.IsDoubleStackSlot()); |
| 3427 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3428 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3429 | } |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3430 | break; |
| 3431 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3432 | |
| 3433 | default: |
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3434 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3435 | } |
| 3436 | } |
| 3437 | |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3438 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3439 | uint32_t stack_adjustment, bool is_float) { |
| 3440 | if (source.IsStackSlot()) { |
| 3441 | DCHECK(is_float); |
| 3442 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3443 | } else if (source.IsDoubleStackSlot()) { |
| 3444 | DCHECK(!is_float); |
| 3445 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3446 | } else { |
| 3447 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3448 | if (is_float) { |
| 3449 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3450 | codegen_->Move(stack_temp, source); |
| 3451 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3452 | } else { |
| 3453 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3454 | codegen_->Move(stack_temp, source); |
| 3455 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3456 | } |
| 3457 | } |
| 3458 | } |
| 3459 | |
| 3460 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3461 | DataType::Type type = rem->GetResultType(); |
| 3462 | bool is_float = type == DataType::Type::kFloat32; |
| 3463 | size_t elem_size = DataType::Size(type); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3464 | LocationSummary* locations = rem->GetLocations(); |
| 3465 | Location first = locations->InAt(0); |
| 3466 | Location second = locations->InAt(1); |
| 3467 | Location out = locations->Out(); |
| 3468 | |
| 3469 | // Create stack space for 2 elements. |
| 3470 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3471 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3472 | |
| 3473 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3474 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3475 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3476 | |
| 3477 | // Loop doing FPREM until we stabilize. |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3478 | NearLabel retry; |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3479 | __ Bind(&retry); |
| 3480 | __ fprem(); |
| 3481 | |
| 3482 | // Move FP status to AX. |
| 3483 | __ fstsw(); |
| 3484 | |
| 3485 | // And see if the argument reduction is complete. This is signaled by the |
| 3486 | // C2 FPU flag bit set to 0. |
| 3487 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3488 | __ j(kNotEqual, &retry); |
| 3489 | |
| 3490 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3491 | // Store FP top of stack to real stack. |
| 3492 | if (is_float) { |
| 3493 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3494 | } else { |
| 3495 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3496 | } |
| 3497 | |
| 3498 | // Pop the 2 items from the FP stack. |
| 3499 | __ fucompp(); |
| 3500 | |
| 3501 | // Load the value from the stack into an XMM register. |
| 3502 | DCHECK(out.IsFpuRegister()) << out; |
| 3503 | if (is_float) { |
| 3504 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3505 | } else { |
| 3506 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3507 | } |
| 3508 | |
| 3509 | // And remove the temporary stack space we allocated. |
| 3510 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3511 | } |
| 3512 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3513 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3514 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3515 | |
| 3516 | LocationSummary* locations = instruction->GetLocations(); |
| 3517 | Location second = locations->InAt(1); |
| 3518 | DCHECK(second.IsConstant()); |
| 3519 | |
| 3520 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3521 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3522 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3523 | |
| 3524 | DCHECK(imm == 1 || imm == -1); |
| 3525 | |
| 3526 | switch (instruction->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3527 | case DataType::Type::kInt32: { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3528 | if (instruction->IsRem()) { |
| 3529 | __ xorl(output_register, output_register); |
| 3530 | } else { |
| 3531 | __ movl(output_register, input_register); |
| 3532 | if (imm == -1) { |
| 3533 | __ negl(output_register); |
| 3534 | } |
| 3535 | } |
| 3536 | break; |
| 3537 | } |
| 3538 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3539 | case DataType::Type::kInt64: { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3540 | if (instruction->IsRem()) { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3541 | __ xorl(output_register, output_register); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3542 | } else { |
| 3543 | __ movq(output_register, input_register); |
| 3544 | if (imm == -1) { |
| 3545 | __ negq(output_register); |
| 3546 | } |
| 3547 | } |
| 3548 | break; |
| 3549 | } |
| 3550 | |
| 3551 | default: |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3552 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3553 | } |
| 3554 | } |
| 3555 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3556 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3557 | LocationSummary* locations = instruction->GetLocations(); |
| 3558 | Location second = locations->InAt(1); |
| 3559 | |
| 3560 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3561 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3562 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3563 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3564 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3565 | uint64_t abs_imm = AbsOrMin(imm); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3566 | |
| 3567 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3568 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3569 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3570 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3571 | __ testl(numerator, numerator); |
| 3572 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3573 | int shift = CTZ(imm); |
| 3574 | __ sarl(tmp, Immediate(shift)); |
| 3575 | |
| 3576 | if (imm < 0) { |
| 3577 | __ negl(tmp); |
| 3578 | } |
| 3579 | |
| 3580 | __ movl(output_register, tmp); |
| 3581 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3582 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3583 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3584 | |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3585 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3586 | __ addq(rdx, numerator); |
| 3587 | __ testq(numerator, numerator); |
| 3588 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3589 | int shift = CTZ(imm); |
| 3590 | __ sarq(rdx, Immediate(shift)); |
| 3591 | |
| 3592 | if (imm < 0) { |
| 3593 | __ negq(rdx); |
| 3594 | } |
| 3595 | |
| 3596 | __ movq(output_register, rdx); |
| 3597 | } |
| 3598 | } |
| 3599 | |
| 3600 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3601 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3602 | |
| 3603 | LocationSummary* locations = instruction->GetLocations(); |
| 3604 | Location second = locations->InAt(1); |
| 3605 | |
| 3606 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3607 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3608 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3609 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3610 | : locations->Out().AsRegister<CpuRegister>(); |
| 3611 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3612 | |
| 3613 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3614 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3615 | if (instruction->IsDiv()) { |
| 3616 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3617 | } else { |
| 3618 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3619 | } |
| 3620 | |
| 3621 | int64_t magic; |
| 3622 | int shift; |
| 3623 | |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3624 | // TODO: can these branches be written as one? |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3625 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3626 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3627 | |
| 3628 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3629 | |
| 3630 | __ movl(numerator, eax); |
| 3631 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3632 | __ movl(eax, Immediate(magic)); |
| 3633 | __ imull(numerator); |
| 3634 | |
| 3635 | if (imm > 0 && magic < 0) { |
| 3636 | __ addl(edx, numerator); |
| 3637 | } else if (imm < 0 && magic > 0) { |
| 3638 | __ subl(edx, numerator); |
| 3639 | } |
| 3640 | |
| 3641 | if (shift != 0) { |
| 3642 | __ sarl(edx, Immediate(shift)); |
| 3643 | } |
| 3644 | |
| 3645 | __ movl(eax, edx); |
| 3646 | __ shrl(edx, Immediate(31)); |
| 3647 | __ addl(edx, eax); |
| 3648 | |
| 3649 | if (instruction->IsRem()) { |
| 3650 | __ movl(eax, numerator); |
| 3651 | __ imull(edx, Immediate(imm)); |
| 3652 | __ subl(eax, edx); |
| 3653 | __ movl(edx, eax); |
| 3654 | } else { |
| 3655 | __ movl(eax, edx); |
| 3656 | } |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3657 | } else { |
| 3658 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3659 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3660 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3661 | |
| 3662 | CpuRegister rax = eax; |
| 3663 | CpuRegister rdx = edx; |
| 3664 | |
| 3665 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3666 | |
| 3667 | // Save the numerator. |
| 3668 | __ movq(numerator, rax); |
| 3669 | |
| 3670 | // RAX = magic |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3671 | codegen_->Load64BitValue(rax, magic); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3672 | |
| 3673 | // RDX:RAX = magic * numerator |
| 3674 | __ imulq(numerator); |
| 3675 | |
| 3676 | if (imm > 0 && magic < 0) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3677 | // RDX += numerator |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3678 | __ addq(rdx, numerator); |
| 3679 | } else if (imm < 0 && magic > 0) { |
| 3680 | // RDX -= numerator |
| 3681 | __ subq(rdx, numerator); |
| 3682 | } |
| 3683 | |
| 3684 | // Shift if needed. |
| 3685 | if (shift != 0) { |
| 3686 | __ sarq(rdx, Immediate(shift)); |
| 3687 | } |
| 3688 | |
| 3689 | // RDX += 1 if RDX < 0 |
| 3690 | __ movq(rax, rdx); |
| 3691 | __ shrq(rdx, Immediate(63)); |
| 3692 | __ addq(rdx, rax); |
| 3693 | |
| 3694 | if (instruction->IsRem()) { |
| 3695 | __ movq(rax, numerator); |
| 3696 | |
| 3697 | if (IsInt<32>(imm)) { |
| 3698 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3699 | } else { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3700 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | __ subq(rax, rdx); |
| 3704 | __ movq(rdx, rax); |
| 3705 | } else { |
| 3706 | __ movq(rax, rdx); |
| 3707 | } |
| 3708 | } |
| 3709 | } |
| 3710 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3711 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3712 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3713 | DataType::Type type = instruction->GetResultType(); |
| 3714 | DCHECK(type == DataType::Type::kInt32 || type == DataType::Type::kInt64); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3715 | |
| 3716 | bool is_div = instruction->IsDiv(); |
| 3717 | LocationSummary* locations = instruction->GetLocations(); |
| 3718 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3719 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3720 | Location second = locations->InAt(1); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3721 | |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3722 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3723 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3724 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3725 | if (second.IsConstant()) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3726 | int64_t imm = Int64FromConstant(second.GetConstant()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3727 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3728 | if (imm == 0) { |
| 3729 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3730 | } else if (imm == 1 || imm == -1) { |
| 3731 | DivRemOneOrMinusOne(instruction); |
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3732 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3733 | DivByPowerOfTwo(instruction->AsDiv()); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3734 | } else { |
| 3735 | DCHECK(imm <= -2 || imm >= 2); |
| 3736 | GenerateDivRemWithAnyConstant(instruction); |
| 3737 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3738 | } else { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3739 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3740 | new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86_64( |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3741 | instruction, out.AsRegister(), type, is_div); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3742 | codegen_->AddSlowPath(slow_path); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3743 | |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3744 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3745 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3746 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3747 | // 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] | 3748 | if (type == DataType::Type::kInt32) { |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3749 | __ cmpl(second_reg, Immediate(-1)); |
| 3750 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3751 | // edx:eax <- sign-extended of eax |
| 3752 | __ cdq(); |
| 3753 | // eax = quotient, edx = remainder |
| 3754 | __ idivl(second_reg); |
| 3755 | } else { |
| 3756 | __ cmpq(second_reg, Immediate(-1)); |
| 3757 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3758 | // rdx:rax <- sign-extended of rax |
| 3759 | __ cqo(); |
| 3760 | // rax = quotient, rdx = remainder |
| 3761 | __ idivq(second_reg); |
| 3762 | } |
| 3763 | __ Bind(slow_path->GetExitLabel()); |
| 3764 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3765 | } |
| 3766 | |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3767 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3768 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3769 | new (GetGraph()->GetAllocator()) LocationSummary(div, LocationSummary::kNoCall); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3770 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3771 | case DataType::Type::kInt32: |
| 3772 | case DataType::Type::kInt64: { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3773 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3774 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3775 | locations->SetOut(Location::SameAsFirstInput()); |
| 3776 | // Intel uses edx:eax as the dividend. |
| 3777 | locations->AddTemp(Location::RegisterLocation(RDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3778 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3779 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3780 | // output and request another temp. |
| 3781 | if (div->InputAt(1)->IsConstant()) { |
| 3782 | locations->AddTemp(Location::RequiresRegister()); |
| 3783 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3784 | break; |
| 3785 | } |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3786 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3787 | case DataType::Type::kFloat32: |
| 3788 | case DataType::Type::kFloat64: { |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3789 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3790 | locations->SetInAt(1, Location::Any()); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3791 | locations->SetOut(Location::SameAsFirstInput()); |
| 3792 | break; |
| 3793 | } |
| 3794 | |
| 3795 | default: |
| 3796 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3797 | } |
| 3798 | } |
| 3799 | |
| 3800 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3801 | LocationSummary* locations = div->GetLocations(); |
| 3802 | Location first = locations->InAt(0); |
| 3803 | Location second = locations->InAt(1); |
| 3804 | DCHECK(first.Equals(locations->Out())); |
| 3805 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3806 | DataType::Type type = div->GetResultType(); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3807 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3808 | case DataType::Type::kInt32: |
| 3809 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3810 | GenerateDivRemIntegral(div); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3811 | break; |
| 3812 | } |
| 3813 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3814 | case DataType::Type::kFloat32: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3815 | if (second.IsFpuRegister()) { |
| 3816 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3817 | } else if (second.IsConstant()) { |
| 3818 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3819 | codegen_->LiteralFloatAddress( |
| 3820 | second.GetConstant()->AsFloatConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3821 | } else { |
| 3822 | DCHECK(second.IsStackSlot()); |
| 3823 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3824 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3825 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3826 | break; |
| 3827 | } |
| 3828 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3829 | case DataType::Type::kFloat64: { |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3830 | if (second.IsFpuRegister()) { |
| 3831 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3832 | } else if (second.IsConstant()) { |
| 3833 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3834 | codegen_->LiteralDoubleAddress( |
| 3835 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3836 | } else { |
| 3837 | DCHECK(second.IsDoubleStackSlot()); |
| 3838 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3839 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3840 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3841 | break; |
| 3842 | } |
| 3843 | |
| 3844 | default: |
| 3845 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3846 | } |
| 3847 | } |
| 3848 | |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3849 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3850 | DataType::Type type = rem->GetResultType(); |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3851 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3852 | new (GetGraph()->GetAllocator()) LocationSummary(rem, LocationSummary::kNoCall); |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3853 | |
| 3854 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3855 | case DataType::Type::kInt32: |
| 3856 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3857 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3858 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3859 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3860 | locations->SetOut(Location::RegisterLocation(RDX)); |
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3861 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3862 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3863 | // output and request another temp. |
| 3864 | if (rem->InputAt(1)->IsConstant()) { |
| 3865 | locations->AddTemp(Location::RequiresRegister()); |
| 3866 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3867 | break; |
| 3868 | } |
| 3869 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3870 | case DataType::Type::kFloat32: |
| 3871 | case DataType::Type::kFloat64: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3872 | locations->SetInAt(0, Location::Any()); |
| 3873 | locations->SetInAt(1, Location::Any()); |
| 3874 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3875 | locations->AddTemp(Location::RegisterLocation(RAX)); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3876 | break; |
| 3877 | } |
| 3878 | |
| 3879 | default: |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3880 | LOG(FATAL) << "Unexpected rem type " << type; |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3881 | } |
| 3882 | } |
| 3883 | |
| 3884 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3885 | DataType::Type type = rem->GetResultType(); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3886 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3887 | case DataType::Type::kInt32: |
| 3888 | case DataType::Type::kInt64: { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3889 | GenerateDivRemIntegral(rem); |
| 3890 | break; |
| 3891 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3892 | case DataType::Type::kFloat32: |
| 3893 | case DataType::Type::kFloat64: { |
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3894 | GenerateRemFP(rem); |
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3895 | break; |
| 3896 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3897 | default: |
| 3898 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3899 | } |
| 3900 | } |
| 3901 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3902 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 3903 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 3904 | switch (minmax->GetResultType()) { |
| 3905 | case DataType::Type::kInt32: |
| 3906 | case DataType::Type::kInt64: |
| 3907 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3908 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3909 | locations->SetOut(Location::SameAsFirstInput()); |
| 3910 | break; |
| 3911 | case DataType::Type::kFloat32: |
| 3912 | case DataType::Type::kFloat64: |
| 3913 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3914 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3915 | // The following is sub-optimal, but all we can do for now. It would be fine to also accept |
| 3916 | // the second input to be the output (we can simply swap inputs). |
| 3917 | locations->SetOut(Location::SameAsFirstInput()); |
| 3918 | break; |
| 3919 | default: |
| 3920 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 3921 | } |
| 3922 | } |
| 3923 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 3924 | void InstructionCodeGeneratorX86_64::GenerateMinMaxInt(LocationSummary* locations, |
| 3925 | bool is_min, |
| 3926 | DataType::Type type) { |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3927 | Location op1_loc = locations->InAt(0); |
| 3928 | Location op2_loc = locations->InAt(1); |
| 3929 | |
| 3930 | // Shortcut for same input locations. |
| 3931 | if (op1_loc.Equals(op2_loc)) { |
| 3932 | // Can return immediately, as op1_loc == out_loc. |
| 3933 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for |
| 3934 | // a copy here. |
| 3935 | DCHECK(locations->Out().Equals(op1_loc)); |
| 3936 | return; |
| 3937 | } |
| 3938 | |
| 3939 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3940 | CpuRegister op2 = op2_loc.AsRegister<CpuRegister>(); |
| 3941 | |
| 3942 | // (out := op1) |
| 3943 | // out <=? op2 |
| 3944 | // if out is min jmp done |
| 3945 | // out := op2 |
| 3946 | // done: |
| 3947 | |
| 3948 | if (type == DataType::Type::kInt64) { |
| 3949 | __ cmpq(out, op2); |
| 3950 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ true); |
| 3951 | } else { |
| 3952 | DCHECK_EQ(type, DataType::Type::kInt32); |
| 3953 | __ cmpl(out, op2); |
| 3954 | __ cmov(is_min ? Condition::kGreater : Condition::kLess, out, op2, /*is64bit*/ false); |
| 3955 | } |
| 3956 | } |
| 3957 | |
| 3958 | void InstructionCodeGeneratorX86_64::GenerateMinMaxFP(LocationSummary* locations, |
| 3959 | bool is_min, |
| 3960 | DataType::Type type) { |
| 3961 | Location op1_loc = locations->InAt(0); |
| 3962 | Location op2_loc = locations->InAt(1); |
| 3963 | Location out_loc = locations->Out(); |
| 3964 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| 3965 | |
| 3966 | // Shortcut for same input locations. |
| 3967 | if (op1_loc.Equals(op2_loc)) { |
| 3968 | DCHECK(out_loc.Equals(op1_loc)); |
| 3969 | return; |
| 3970 | } |
| 3971 | |
| 3972 | // (out := op1) |
| 3973 | // out <=? op2 |
| 3974 | // if Nan jmp Nan_label |
| 3975 | // if out is min jmp done |
| 3976 | // if op2 is min jmp op2_label |
| 3977 | // handle -0/+0 |
| 3978 | // jmp done |
| 3979 | // Nan_label: |
| 3980 | // out := NaN |
| 3981 | // op2_label: |
| 3982 | // out := op2 |
| 3983 | // done: |
| 3984 | // |
| 3985 | // This removes one jmp, but needs to copy one input (op1) to out. |
| 3986 | // |
| 3987 | // TODO: This is straight from Quick. Make NaN an out-of-line slowpath? |
| 3988 | |
| 3989 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); |
| 3990 | |
| 3991 | NearLabel nan, done, op2_label; |
| 3992 | if (type == DataType::Type::kFloat64) { |
| 3993 | __ ucomisd(out, op2); |
| 3994 | } else { |
| 3995 | DCHECK_EQ(type, DataType::Type::kFloat32); |
| 3996 | __ ucomiss(out, op2); |
| 3997 | } |
| 3998 | |
| 3999 | __ j(Condition::kParityEven, &nan); |
| 4000 | |
| 4001 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); |
| 4002 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); |
| 4003 | |
| 4004 | // Handle 0.0/-0.0. |
| 4005 | if (is_min) { |
| 4006 | if (type == DataType::Type::kFloat64) { |
| 4007 | __ orpd(out, op2); |
| 4008 | } else { |
| 4009 | __ orps(out, op2); |
| 4010 | } |
| 4011 | } else { |
| 4012 | if (type == DataType::Type::kFloat64) { |
| 4013 | __ andpd(out, op2); |
| 4014 | } else { |
| 4015 | __ andps(out, op2); |
| 4016 | } |
| 4017 | } |
| 4018 | __ jmp(&done); |
| 4019 | |
| 4020 | // NaN handling. |
| 4021 | __ Bind(&nan); |
| 4022 | if (type == DataType::Type::kFloat64) { |
| 4023 | __ movsd(out, codegen_->LiteralInt64Address(INT64_C(0x7FF8000000000000))); |
| 4024 | } else { |
| 4025 | __ movss(out, codegen_->LiteralInt32Address(INT32_C(0x7FC00000))); |
| 4026 | } |
| 4027 | __ jmp(&done); |
| 4028 | |
| 4029 | // out := op2; |
| 4030 | __ Bind(&op2_label); |
| 4031 | if (type == DataType::Type::kFloat64) { |
| 4032 | __ movsd(out, op2); |
| 4033 | } else { |
| 4034 | __ movss(out, op2); |
| 4035 | } |
| 4036 | |
| 4037 | // Done. |
| 4038 | __ Bind(&done); |
| 4039 | } |
| 4040 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4041 | void InstructionCodeGeneratorX86_64::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4042 | DataType::Type type = minmax->GetResultType(); |
| 4043 | switch (type) { |
| 4044 | case DataType::Type::kInt32: |
| 4045 | case DataType::Type::kInt64: |
| 4046 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); |
| 4047 | break; |
| 4048 | case DataType::Type::kFloat32: |
| 4049 | case DataType::Type::kFloat64: |
| 4050 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); |
| 4051 | break; |
| 4052 | default: |
| 4053 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4054 | } |
| 4055 | } |
| 4056 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4057 | void LocationsBuilderX86_64::VisitMin(HMin* min) { |
| 4058 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4059 | } |
| 4060 | |
| 4061 | void InstructionCodeGeneratorX86_64::VisitMin(HMin* min) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4062 | GenerateMinMax(min, /*is_min*/ true); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | void LocationsBuilderX86_64::VisitMax(HMax* max) { |
| 4066 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4067 | } |
| 4068 | |
| 4069 | void InstructionCodeGeneratorX86_64::VisitMax(HMax* max) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4070 | GenerateMinMax(max, /*is_min*/ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4071 | } |
| 4072 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4073 | void LocationsBuilderX86_64::VisitAbs(HAbs* abs) { |
| 4074 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4075 | switch (abs->GetResultType()) { |
| 4076 | case DataType::Type::kInt32: |
| 4077 | case DataType::Type::kInt64: |
| 4078 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4079 | locations->SetOut(Location::SameAsFirstInput()); |
| 4080 | locations->AddTemp(Location::RequiresRegister()); |
| 4081 | break; |
| 4082 | case DataType::Type::kFloat32: |
| 4083 | case DataType::Type::kFloat64: |
| 4084 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4085 | locations->SetOut(Location::SameAsFirstInput()); |
| 4086 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4087 | break; |
| 4088 | default: |
| 4089 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4090 | } |
| 4091 | } |
| 4092 | |
| 4093 | void InstructionCodeGeneratorX86_64::VisitAbs(HAbs* abs) { |
| 4094 | LocationSummary* locations = abs->GetLocations(); |
| 4095 | switch (abs->GetResultType()) { |
| 4096 | case DataType::Type::kInt32: { |
| 4097 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4098 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4099 | // Create mask. |
| 4100 | __ movl(mask, out); |
| 4101 | __ sarl(mask, Immediate(31)); |
| 4102 | // Add mask. |
| 4103 | __ addl(out, mask); |
| 4104 | __ xorl(out, mask); |
| 4105 | break; |
| 4106 | } |
| 4107 | case DataType::Type::kInt64: { |
| 4108 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4109 | CpuRegister mask = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4110 | // Create mask. |
| 4111 | __ movq(mask, out); |
| 4112 | __ sarq(mask, Immediate(63)); |
| 4113 | // Add mask. |
| 4114 | __ addq(out, mask); |
| 4115 | __ xorq(out, mask); |
| 4116 | break; |
| 4117 | } |
| 4118 | case DataType::Type::kFloat32: { |
| 4119 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4120 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4121 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x7FFFFFFF))); |
| 4122 | __ andps(out, mask); |
| 4123 | break; |
| 4124 | } |
| 4125 | case DataType::Type::kFloat64: { |
| 4126 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4127 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4128 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x7FFFFFFFFFFFFFFF))); |
| 4129 | __ andpd(out, mask); |
| 4130 | break; |
| 4131 | } |
| 4132 | default: |
| 4133 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); |
| 4134 | } |
| 4135 | } |
| 4136 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4137 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4138 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4139 | locations->SetInAt(0, Location::Any()); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4143 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4144 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86_64(instruction); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4145 | codegen_->AddSlowPath(slow_path); |
| 4146 | |
| 4147 | LocationSummary* locations = instruction->GetLocations(); |
| 4148 | Location value = locations->InAt(0); |
| 4149 | |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4150 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4151 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4152 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4153 | case DataType::Type::kInt8: |
| 4154 | case DataType::Type::kUint16: |
| 4155 | case DataType::Type::kInt16: |
| 4156 | case DataType::Type::kInt32: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4157 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4158 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4159 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4160 | } else if (value.IsStackSlot()) { |
| 4161 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4162 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4163 | } else { |
| 4164 | DCHECK(value.IsConstant()) << value; |
| 4165 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4166 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4167 | } |
| 4168 | } |
| 4169 | break; |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4170 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4171 | case DataType::Type::kInt64: { |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4172 | if (value.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4173 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4174 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4175 | } else if (value.IsDoubleStackSlot()) { |
| 4176 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 4177 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4178 | } else { |
| 4179 | DCHECK(value.IsConstant()) << value; |
| 4180 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4181 | __ jmp(slow_path->GetEntryLabel()); |
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4182 | } |
| 4183 | } |
| 4184 | break; |
| 4185 | } |
| 4186 | default: |
| 4187 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4188 | } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4189 | } |
| 4190 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4191 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 4192 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4193 | |
| 4194 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4195 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4196 | |
| 4197 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4198 | case DataType::Type::kInt32: |
| 4199 | case DataType::Type::kInt64: { |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4200 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4201 | // The shift count needs to be in CL. |
| 4202 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 4203 | locations->SetOut(Location::SameAsFirstInput()); |
| 4204 | break; |
| 4205 | } |
| 4206 | default: |
| 4207 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 4212 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4213 | |
| 4214 | LocationSummary* locations = op->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4215 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4216 | Location second = locations->InAt(1); |
| 4217 | |
| 4218 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4219 | case DataType::Type::kInt32: { |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4220 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4221 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4222 | if (op->IsShl()) { |
| 4223 | __ shll(first_reg, second_reg); |
| 4224 | } else if (op->IsShr()) { |
| 4225 | __ sarl(first_reg, second_reg); |
| 4226 | } else { |
| 4227 | __ shrl(first_reg, second_reg); |
| 4228 | } |
| 4229 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4230 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4231 | if (op->IsShl()) { |
| 4232 | __ shll(first_reg, imm); |
| 4233 | } else if (op->IsShr()) { |
| 4234 | __ sarl(first_reg, imm); |
| 4235 | } else { |
| 4236 | __ shrl(first_reg, imm); |
| 4237 | } |
| 4238 | } |
| 4239 | break; |
| 4240 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4241 | case DataType::Type::kInt64: { |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4242 | if (second.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4243 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4244 | if (op->IsShl()) { |
| 4245 | __ shlq(first_reg, second_reg); |
| 4246 | } else if (op->IsShr()) { |
| 4247 | __ sarq(first_reg, second_reg); |
| 4248 | } else { |
| 4249 | __ shrq(first_reg, second_reg); |
| 4250 | } |
| 4251 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4252 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4253 | if (op->IsShl()) { |
| 4254 | __ shlq(first_reg, imm); |
| 4255 | } else if (op->IsShr()) { |
| 4256 | __ sarq(first_reg, imm); |
| 4257 | } else { |
| 4258 | __ shrq(first_reg, imm); |
| 4259 | } |
| 4260 | } |
| 4261 | break; |
| 4262 | } |
| 4263 | default: |
| 4264 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 4265 | UNREACHABLE(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4266 | } |
| 4267 | } |
| 4268 | |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4269 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 4270 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4271 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4272 | |
| 4273 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4274 | case DataType::Type::kInt32: |
| 4275 | case DataType::Type::kInt64: { |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4276 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4277 | // The shift count needs to be in CL (unless it is a constant). |
| 4278 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 4279 | locations->SetOut(Location::SameAsFirstInput()); |
| 4280 | break; |
| 4281 | } |
| 4282 | default: |
| 4283 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4284 | UNREACHABLE(); |
| 4285 | } |
| 4286 | } |
| 4287 | |
| 4288 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 4289 | LocationSummary* locations = ror->GetLocations(); |
| 4290 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4291 | Location second = locations->InAt(1); |
| 4292 | |
| 4293 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4294 | case DataType::Type::kInt32: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4295 | if (second.IsRegister()) { |
| 4296 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4297 | __ rorl(first_reg, second_reg); |
| 4298 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4299 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4300 | __ rorl(first_reg, imm); |
| 4301 | } |
| 4302 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4303 | case DataType::Type::kInt64: |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4304 | if (second.IsRegister()) { |
| 4305 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 4306 | __ rorq(first_reg, second_reg); |
| 4307 | } else { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4308 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4309 | __ rorq(first_reg, imm); |
| 4310 | } |
| 4311 | break; |
| 4312 | default: |
| 4313 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4314 | UNREACHABLE(); |
| 4315 | } |
| 4316 | } |
| 4317 | |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4318 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 4319 | HandleShift(shl); |
| 4320 | } |
| 4321 | |
| 4322 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 4323 | HandleShift(shl); |
| 4324 | } |
| 4325 | |
| 4326 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 4327 | HandleShift(shr); |
| 4328 | } |
| 4329 | |
| 4330 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 4331 | HandleShift(shr); |
| 4332 | } |
| 4333 | |
| 4334 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 4335 | HandleShift(ushr); |
| 4336 | } |
| 4337 | |
| 4338 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 4339 | HandleShift(ushr); |
| 4340 | } |
| 4341 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4342 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4343 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4344 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4345 | InvokeRuntimeCallingConvention calling_convention; |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4346 | if (instruction->IsStringAlloc()) { |
| 4347 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4348 | } else { |
| 4349 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4350 | } |
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4351 | locations->SetOut(Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4355 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4356 | // of poisoning the reference. |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4357 | if (instruction->IsStringAlloc()) { |
| 4358 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4359 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4360 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4361 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 4362 | __ call(Address(temp, code_offset.SizeValue())); |
| 4363 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4364 | } else { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4365 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | 0d3998b | 2017-01-12 15:35:12 +0000 | [diff] [blame] | 4366 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4367 | DCHECK(!codegen_->IsLeafMethod()); |
| 4368 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4369 | } |
| 4370 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4371 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4372 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 4373 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4374 | InvokeRuntimeCallingConvention calling_convention; |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4375 | locations->SetOut(Location::RegisterLocation(RAX)); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4376 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4377 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4381 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4382 | // of poisoning the reference. |
| Nicolas Geoffray | b048cb7 | 2017-01-23 22:50:24 +0000 | [diff] [blame] | 4383 | QuickEntrypointEnum entrypoint = |
| 4384 | CodeGenerator::GetArrayAllocationEntrypoint(instruction->GetLoadClass()->GetClass()); |
| 4385 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4386 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4387 | DCHECK(!codegen_->IsLeafMethod()); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4388 | } |
| 4389 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4390 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4391 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4392 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4393 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4394 | if (location.IsStackSlot()) { |
| 4395 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4396 | } else if (location.IsDoubleStackSlot()) { |
| 4397 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4398 | } |
| 4399 | locations->SetOut(location); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4400 | } |
| 4401 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4402 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4403 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4404 | // Nothing to do, the parameter is already at its location. |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4408 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4409 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4410 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4411 | } |
| 4412 | |
| 4413 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4414 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4415 | // Nothing to do, the method is already at its location. |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4416 | } |
| 4417 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4418 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4419 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4420 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4421 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4422 | locations->SetOut(Location::RequiresRegister()); |
| 4423 | } |
| 4424 | |
| 4425 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4426 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4427 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4428 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4429 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4430 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4431 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4432 | } else { |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4433 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4434 | instruction->GetIndex(), kX86_64PointerSize)); |
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4435 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4436 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4437 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4438 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4439 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4440 | } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4441 | } |
| 4442 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4443 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4444 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4445 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4446 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4447 | locations->SetOut(Location::SameAsFirstInput()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4448 | } |
| 4449 | |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4450 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4451 | LocationSummary* locations = not_->GetLocations(); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4452 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4453 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4454 | Location out = locations->Out(); |
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4455 | switch (not_->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4456 | case DataType::Type::kInt32: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4457 | __ notl(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4458 | break; |
| 4459 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4460 | case DataType::Type::kInt64: |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4461 | __ notq(out.AsRegister<CpuRegister>()); |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4462 | break; |
| 4463 | |
| 4464 | default: |
| 4465 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4466 | } |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4467 | } |
| 4468 | |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4469 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4470 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4471 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4472 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4473 | locations->SetOut(Location::SameAsFirstInput()); |
| 4474 | } |
| 4475 | |
| 4476 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4477 | LocationSummary* locations = bool_not->GetLocations(); |
| 4478 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4479 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4480 | Location out = locations->Out(); |
| 4481 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4482 | } |
| 4483 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4484 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4485 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4486 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4487 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4488 | locations->SetInAt(i, Location::Any()); |
| 4489 | } |
| 4490 | locations->SetOut(Location::Any()); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4491 | } |
| 4492 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4493 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4494 | LOG(FATAL) << "Unimplemented"; |
| 4495 | } |
| 4496 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4497 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4498 | /* |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4499 | * 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] | 4500 | * 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] | 4501 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4502 | */ |
| 4503 | switch (kind) { |
| 4504 | case MemBarrierKind::kAnyAny: { |
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4505 | MemoryFence(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4506 | break; |
| 4507 | } |
| 4508 | case MemBarrierKind::kAnyStore: |
| 4509 | case MemBarrierKind::kLoadAny: |
| 4510 | case MemBarrierKind::kStoreStore: { |
| 4511 | // nop |
| 4512 | break; |
| 4513 | } |
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4514 | case MemBarrierKind::kNTStoreStore: |
| 4515 | // Non-Temporal Store/Store needs an explicit fence. |
| 4516 | MemoryFence(/* non-temporal */ true); |
| 4517 | break; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4518 | } |
| 4519 | } |
| 4520 | |
| 4521 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4522 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4523 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4524 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4525 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4526 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4527 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4528 | object_field_get_with_read_barrier |
| 4529 | ? LocationSummary::kCallOnSlowPath |
| 4530 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4531 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4532 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4533 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4534 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4535 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4536 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4537 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4538 | // The output overlaps for an object field get when read barriers |
| 4539 | // are enabled: we do not want the move to overwrite the object's |
| 4540 | // location, as we need it to emit the read barrier. |
| 4541 | locations->SetOut( |
| 4542 | Location::RequiresRegister(), |
| 4543 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4544 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4545 | } |
| 4546 | |
| 4547 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4548 | const FieldInfo& field_info) { |
| 4549 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4550 | |
| 4551 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4552 | Location base_loc = locations->InAt(0); |
| 4553 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4554 | Location out = locations->Out(); |
| 4555 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4556 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 4557 | DataType::Type load_type = instruction->GetType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4558 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4559 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4560 | switch (load_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4561 | case DataType::Type::kBool: |
| 4562 | case DataType::Type::kUint8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4563 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4564 | break; |
| 4565 | } |
| 4566 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4567 | case DataType::Type::kInt8: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4568 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4569 | break; |
| 4570 | } |
| 4571 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4572 | case DataType::Type::kUint16: { |
| 4573 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4574 | break; |
| 4575 | } |
| 4576 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4577 | case DataType::Type::kInt16: { |
| 4578 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4579 | break; |
| 4580 | } |
| 4581 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4582 | case DataType::Type::kInt32: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4583 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4584 | break; |
| 4585 | } |
| 4586 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4587 | case DataType::Type::kReference: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4588 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4589 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4590 | // Note that a potential implicit null check is handled in this |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 4591 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier call. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4592 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4593 | instruction, out, base, offset, /* needs_null_check */ true); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4594 | if (is_volatile) { |
| 4595 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4596 | } |
| 4597 | } else { |
| 4598 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4599 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4600 | if (is_volatile) { |
| 4601 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4602 | } |
| 4603 | // If read barriers are enabled, emit read barriers other than |
| 4604 | // Baker's using a slow path (and also unpoison the loaded |
| 4605 | // reference, if heap poisoning is enabled). |
| 4606 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4607 | } |
| 4608 | break; |
| 4609 | } |
| 4610 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4611 | case DataType::Type::kInt64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4612 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4613 | break; |
| 4614 | } |
| 4615 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4616 | case DataType::Type::kFloat32: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4617 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4618 | break; |
| 4619 | } |
| 4620 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4621 | case DataType::Type::kFloat64: { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4622 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4623 | break; |
| 4624 | } |
| 4625 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4626 | case DataType::Type::kUint32: |
| 4627 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4628 | case DataType::Type::kVoid: |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4629 | LOG(FATAL) << "Unreachable type " << load_type; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4630 | UNREACHABLE(); |
| 4631 | } |
| 4632 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4633 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4634 | // Potential implicit null checks, in the case of reference |
| 4635 | // fields, are handled in the previous switch statement. |
| 4636 | } else { |
| 4637 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4638 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4639 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4640 | if (is_volatile) { |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 4641 | if (load_type == DataType::Type::kReference) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4642 | // Memory barriers, in the case of references, are also handled |
| 4643 | // in the previous switch statement. |
| 4644 | } else { |
| 4645 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4646 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4647 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4648 | } |
| 4649 | |
| 4650 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4651 | const FieldInfo& field_info) { |
| 4652 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4653 | |
| 4654 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4655 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4656 | DataType::Type field_type = field_info.GetFieldType(); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4657 | bool is_volatile = field_info.IsVolatile(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4658 | bool needs_write_barrier = |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4659 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4660 | |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4661 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4662 | if (DataType::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4663 | if (is_volatile) { |
| 4664 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4665 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4666 | } else { |
| 4667 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4668 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4669 | } else { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4670 | if (is_volatile) { |
| 4671 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4672 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4673 | } else { |
| 4674 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4675 | } |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4676 | } |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4677 | if (needs_write_barrier) { |
| Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4678 | // Temporary registers for the write barrier. |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4679 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4680 | locations->AddTemp(Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4681 | } else if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4682 | // Temporary register for the reference poisoning. |
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4683 | locations->AddTemp(Location::RequiresRegister()); |
| 4684 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4685 | } |
| 4686 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4687 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4688 | const FieldInfo& field_info, |
| 4689 | bool value_can_be_null) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4690 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4691 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4692 | LocationSummary* locations = instruction->GetLocations(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4693 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4694 | Location value = locations->InAt(1); |
| 4695 | bool is_volatile = field_info.IsVolatile(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4696 | DataType::Type field_type = field_info.GetFieldType(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4697 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4698 | |
| 4699 | if (is_volatile) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4700 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4701 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4702 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4703 | bool maybe_record_implicit_null_check_done = false; |
| 4704 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4705 | switch (field_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4706 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4707 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4708 | case DataType::Type::kInt8: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4709 | if (value.IsConstant()) { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4710 | __ movb(Address(base, offset), |
| 4711 | Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4712 | } else { |
| 4713 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4714 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4715 | break; |
| 4716 | } |
| 4717 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4718 | case DataType::Type::kUint16: |
| 4719 | case DataType::Type::kInt16: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4720 | if (value.IsConstant()) { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 4721 | __ movw(Address(base, offset), |
| 4722 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4723 | } else { |
| 4724 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4725 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4726 | break; |
| 4727 | } |
| 4728 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4729 | case DataType::Type::kInt32: |
| 4730 | case DataType::Type::kReference: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4731 | if (value.IsConstant()) { |
| 4732 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4733 | // `field_type == DataType::Type::kReference` implies `v == 0`. |
| 4734 | DCHECK((field_type != DataType::Type::kReference) || (v == 0)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4735 | // Note: if heap poisoning is enabled, no need to poison |
| 4736 | // (negate) `v` if it is a reference, as it would be null. |
| Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4737 | __ movl(Address(base, offset), Immediate(v)); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4738 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4739 | if (kPoisonHeapReferences && field_type == DataType::Type::kReference) { |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4740 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4741 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4742 | __ PoisonHeapReference(temp); |
| 4743 | __ movl(Address(base, offset), temp); |
| 4744 | } else { |
| 4745 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4746 | } |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4747 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4748 | break; |
| 4749 | } |
| 4750 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4751 | case DataType::Type::kInt64: { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4752 | if (value.IsConstant()) { |
| 4753 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4754 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4755 | Address(base, offset + sizeof(int32_t)), |
| 4756 | v, |
| 4757 | instruction); |
| 4758 | maybe_record_implicit_null_check_done = true; |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4759 | } else { |
| 4760 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4761 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4762 | break; |
| 4763 | } |
| 4764 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4765 | case DataType::Type::kFloat32: { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4766 | if (value.IsConstant()) { |
| 4767 | int32_t v = |
| 4768 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4769 | __ movl(Address(base, offset), Immediate(v)); |
| 4770 | } else { |
| 4771 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4772 | } |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4773 | break; |
| 4774 | } |
| 4775 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4776 | case DataType::Type::kFloat64: { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4777 | if (value.IsConstant()) { |
| 4778 | int64_t v = |
| 4779 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4780 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4781 | Address(base, offset + sizeof(int32_t)), |
| 4782 | v, |
| 4783 | instruction); |
| 4784 | maybe_record_implicit_null_check_done = true; |
| 4785 | } else { |
| 4786 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4787 | } |
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4788 | break; |
| 4789 | } |
| 4790 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 4791 | case DataType::Type::kUint32: |
| 4792 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4793 | case DataType::Type::kVoid: |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4794 | LOG(FATAL) << "Unreachable type " << field_type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4795 | UNREACHABLE(); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4796 | } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4797 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4798 | if (!maybe_record_implicit_null_check_done) { |
| 4799 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4800 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4801 | |
| 4802 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4803 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4804 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4805 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4808 | if (is_volatile) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4809 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4810 | } |
| 4811 | } |
| 4812 | |
| 4813 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4814 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4815 | } |
| 4816 | |
| 4817 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4818 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4819 | } |
| 4820 | |
| 4821 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4822 | HandleFieldGet(instruction); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4826 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4827 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4828 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4829 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4830 | HandleFieldGet(instruction); |
| 4831 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4832 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4833 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4834 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4835 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4836 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4837 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4838 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4839 | } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4840 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4841 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4842 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4843 | } |
| 4844 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4845 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4846 | HUnresolvedInstanceFieldGet* instruction) { |
| 4847 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4848 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4849 | instruction, instruction->GetFieldType(), calling_convention); |
| 4850 | } |
| 4851 | |
| 4852 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4853 | HUnresolvedInstanceFieldGet* instruction) { |
| 4854 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4855 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4856 | instruction->GetFieldType(), |
| 4857 | instruction->GetFieldIndex(), |
| 4858 | instruction->GetDexPc(), |
| 4859 | calling_convention); |
| 4860 | } |
| 4861 | |
| 4862 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4863 | HUnresolvedInstanceFieldSet* instruction) { |
| 4864 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4865 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4866 | instruction, instruction->GetFieldType(), calling_convention); |
| 4867 | } |
| 4868 | |
| 4869 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4870 | HUnresolvedInstanceFieldSet* instruction) { |
| 4871 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4872 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4873 | instruction->GetFieldType(), |
| 4874 | instruction->GetFieldIndex(), |
| 4875 | instruction->GetDexPc(), |
| 4876 | calling_convention); |
| 4877 | } |
| 4878 | |
| 4879 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4880 | HUnresolvedStaticFieldGet* instruction) { |
| 4881 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4882 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4883 | instruction, instruction->GetFieldType(), calling_convention); |
| 4884 | } |
| 4885 | |
| 4886 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4887 | HUnresolvedStaticFieldGet* instruction) { |
| 4888 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4889 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4890 | instruction->GetFieldType(), |
| 4891 | instruction->GetFieldIndex(), |
| 4892 | instruction->GetDexPc(), |
| 4893 | calling_convention); |
| 4894 | } |
| 4895 | |
| 4896 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4897 | HUnresolvedStaticFieldSet* instruction) { |
| 4898 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4899 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4900 | instruction, instruction->GetFieldType(), calling_convention); |
| 4901 | } |
| 4902 | |
| 4903 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4904 | HUnresolvedStaticFieldSet* instruction) { |
| 4905 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4906 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4907 | instruction->GetFieldType(), |
| 4908 | instruction->GetFieldIndex(), |
| 4909 | instruction->GetDexPc(), |
| 4910 | calling_convention); |
| 4911 | } |
| 4912 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4913 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4914 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4915 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4916 | ? Location::RequiresRegister() |
| 4917 | : Location::Any(); |
| 4918 | locations->SetInAt(0, loc); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4919 | } |
| 4920 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4921 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4922 | if (CanMoveNullCheckToUser(instruction)) { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4923 | return; |
| 4924 | } |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4925 | LocationSummary* locations = instruction->GetLocations(); |
| 4926 | Location obj = locations->InAt(0); |
| 4927 | |
| 4928 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4929 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4930 | } |
| 4931 | |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4932 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4933 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86_64(instruction); |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4934 | AddSlowPath(slow_path); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4935 | |
| 4936 | LocationSummary* locations = instruction->GetLocations(); |
| 4937 | Location obj = locations->InAt(0); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4938 | |
| 4939 | if (obj.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4940 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4941 | } else if (obj.IsStackSlot()) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4942 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4943 | } else { |
| 4944 | DCHECK(obj.IsConstant()) << obj; |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4945 | DCHECK(obj.GetConstant()->IsNullConstant()); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4946 | __ jmp(slow_path->GetEntryLabel()); |
| 4947 | return; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4948 | } |
| 4949 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4950 | } |
| 4951 | |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4952 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4953 | codegen_->GenerateNullCheck(instruction); |
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4954 | } |
| 4955 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4956 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4957 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4958 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4959 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4960 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 4961 | object_array_get_with_read_barrier |
| 4962 | ? LocationSummary::kCallOnSlowPath |
| 4963 | : LocationSummary::kNoCall); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4964 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4965 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4966 | } |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4967 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4968 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4969 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4970 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4971 | } else { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4972 | // The output overlaps for an object array get when read barriers |
| 4973 | // are enabled: we do not want the move to overwrite the array's |
| 4974 | // location, as we need it to emit the read barrier. |
| 4975 | locations->SetOut( |
| 4976 | Location::RequiresRegister(), |
| 4977 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4978 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4982 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4983 | Location obj_loc = locations->InAt(0); |
| 4984 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4985 | Location index = locations->InAt(1); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4986 | Location out_loc = locations->Out(); |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4987 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4988 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4989 | DataType::Type type = instruction->GetType(); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4990 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4991 | case DataType::Type::kBool: |
| 4992 | case DataType::Type::kUint8: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4993 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4994 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4995 | break; |
| 4996 | } |
| 4997 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4998 | case DataType::Type::kInt8: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4999 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5000 | __ movsxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5001 | break; |
| 5002 | } |
| 5003 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5004 | case DataType::Type::kUint16: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5005 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5006 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5007 | // Branch cases into compressed and uncompressed for each index's type. |
| 5008 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5009 | NearLabel done, not_compressed; |
| Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5010 | __ testb(Address(obj, count_offset), Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5011 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5012 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 5013 | "Expecting 0=compressed, 1=uncompressed"); |
| 5014 | __ j(kNotZero, ¬_compressed); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5015 | __ movzxb(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5016 | __ jmp(&done); |
| 5017 | __ Bind(¬_compressed); |
| 5018 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5019 | __ Bind(&done); |
| 5020 | } else { |
| 5021 | __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5022 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5023 | break; |
| 5024 | } |
| 5025 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5026 | case DataType::Type::kInt16: { |
| 5027 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 5028 | __ movsxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5029 | break; |
| 5030 | } |
| 5031 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5032 | case DataType::Type::kInt32: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5033 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5034 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5035 | break; |
| 5036 | } |
| 5037 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5038 | case DataType::Type::kReference: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5039 | static_assert( |
| 5040 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5041 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5042 | // /* HeapReference<Object> */ out = |
| 5043 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5044 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5045 | // Note that a potential implicit null check is handled in this |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 5046 | // CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier call. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5047 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5048 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5049 | } else { |
| 5050 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5051 | __ movl(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5052 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5053 | // If read barriers are enabled, emit read barriers other than |
| 5054 | // Baker's using a slow path (and also unpoison the loaded |
| 5055 | // reference, if heap poisoning is enabled). |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5056 | if (index.IsConstant()) { |
| 5057 | uint32_t offset = |
| 5058 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5059 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5060 | } else { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5061 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5062 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5063 | } |
| 5064 | } |
| 5065 | break; |
| 5066 | } |
| 5067 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5068 | case DataType::Type::kInt64: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5069 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5070 | __ movq(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5071 | break; |
| 5072 | } |
| 5073 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5074 | case DataType::Type::kFloat32: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5075 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5076 | __ movss(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5077 | break; |
| 5078 | } |
| 5079 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5080 | case DataType::Type::kFloat64: { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5081 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5082 | __ movsd(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5083 | break; |
| 5084 | } |
| 5085 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5086 | case DataType::Type::kUint32: |
| 5087 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5088 | case DataType::Type::kVoid: |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5089 | LOG(FATAL) << "Unreachable type " << type; |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5090 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5091 | } |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5092 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5093 | if (type == DataType::Type::kReference) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5094 | // Potential implicit null checks, in the case of reference |
| 5095 | // arrays, are handled in the previous switch statement. |
| 5096 | } else { |
| 5097 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5098 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5099 | } |
| 5100 | |
| 5101 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5102 | DataType::Type value_type = instruction->GetComponentType(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5103 | |
| 5104 | bool needs_write_barrier = |
| 5105 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5106 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5107 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5108 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5109 | instruction, |
| Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5110 | may_need_runtime_call_for_type_check ? |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5111 | LocationSummary::kCallOnSlowPath : |
| 5112 | LocationSummary::kNoCall); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5113 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5114 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5115 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5116 | if (DataType::IsFloatingPointType(value_type)) { |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5117 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5118 | } else { |
| 5119 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5120 | } |
| 5121 | |
| 5122 | if (needs_write_barrier) { |
| 5123 | // Temporary registers for the write barrier. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5124 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5125 | locations->AddTemp(Location::RequiresRegister()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5126 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5127 | } |
| 5128 | |
| 5129 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 5130 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5131 | Location array_loc = locations->InAt(0); |
| 5132 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5133 | Location index = locations->InAt(1); |
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5134 | Location value = locations->InAt(2); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5135 | DataType::Type value_type = instruction->GetComponentType(); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5136 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5137 | bool needs_write_barrier = |
| 5138 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5139 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5140 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5141 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5142 | |
| 5143 | switch (value_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5144 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5145 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5146 | case DataType::Type::kInt8: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5147 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5148 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_1, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5149 | if (value.IsRegister()) { |
| 5150 | __ movb(address, value.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5151 | } else { |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5152 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5153 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5154 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5155 | break; |
| 5156 | } |
| 5157 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5158 | case DataType::Type::kUint16: |
| 5159 | case DataType::Type::kInt16: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5160 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5161 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_2, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5162 | if (value.IsRegister()) { |
| 5163 | __ movw(address, value.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5164 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5165 | DCHECK(value.IsConstant()) << value; |
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5166 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5167 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5168 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5169 | break; |
| 5170 | } |
| 5171 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5172 | case DataType::Type::kReference: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5173 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5174 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5175 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5176 | if (!value.IsRegister()) { |
| 5177 | // Just setting null. |
| 5178 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5179 | DCHECK(value.IsConstant()) << value; |
| 5180 | __ movl(address, Immediate(0)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5181 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5182 | DCHECK(!needs_write_barrier); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5183 | DCHECK(!may_need_runtime_call_for_type_check); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5184 | break; |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5185 | } |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5186 | |
| 5187 | DCHECK(needs_write_barrier); |
| 5188 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5189 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5190 | // short when Baker read barriers are enabled. |
| 5191 | Label done; |
| 5192 | NearLabel not_null, do_put; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5193 | SlowPathCode* slow_path = nullptr; |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5194 | Location temp_loc = locations->GetTemp(0); |
| 5195 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5196 | if (may_need_runtime_call_for_type_check) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5197 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86_64(instruction); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5198 | codegen_->AddSlowPath(slow_path); |
| 5199 | if (instruction->GetValueCanBeNull()) { |
| 5200 | __ testl(register_value, register_value); |
| 5201 | __ j(kNotEqual, ¬_null); |
| 5202 | __ movl(address, Immediate(0)); |
| 5203 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5204 | __ jmp(&done); |
| 5205 | __ Bind(¬_null); |
| 5206 | } |
| 5207 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5208 | // Note that when Baker read barriers are enabled, the type |
| 5209 | // checks are performed without read barriers. This is fine, |
| 5210 | // even in the case where a class object is in the from-space |
| 5211 | // after the flip, as a comparison involving such a type would |
| 5212 | // not produce a false positive; it may of course produce a |
| 5213 | // false negative, in which case we would take the ArraySet |
| 5214 | // slow path. |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5215 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5216 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5217 | __ movl(temp, Address(array, class_offset)); |
| 5218 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5219 | __ MaybeUnpoisonHeapReference(temp); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5220 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5221 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5222 | __ movl(temp, Address(temp, component_offset)); |
| 5223 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5224 | // nor the object reference in `register_value->klass`, as |
| 5225 | // we are comparing two poisoned references. |
| 5226 | __ cmpl(temp, Address(register_value, class_offset)); |
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5227 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5228 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5229 | __ j(kEqual, &do_put); |
| 5230 | // If heap poisoning is enabled, the `temp` reference has |
| 5231 | // not been unpoisoned yet; unpoison it now. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5232 | __ MaybeUnpoisonHeapReference(temp); |
| 5233 | |
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5234 | // If heap poisoning is enabled, no need to unpoison the |
| 5235 | // heap reference loaded below, as it is only used for a |
| 5236 | // comparison with null. |
| 5237 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5238 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5239 | __ Bind(&do_put); |
| 5240 | } else { |
| 5241 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5242 | } |
| 5243 | } |
| 5244 | |
| 5245 | if (kPoisonHeapReferences) { |
| 5246 | __ movl(temp, register_value); |
| 5247 | __ PoisonHeapReference(temp); |
| 5248 | __ movl(address, temp); |
| 5249 | } else { |
| 5250 | __ movl(address, register_value); |
| 5251 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5252 | if (!may_need_runtime_call_for_type_check) { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5253 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5254 | } |
| 5255 | |
| 5256 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 5257 | codegen_->MarkGCCard( |
| 5258 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 5259 | __ Bind(&done); |
| 5260 | |
| 5261 | if (slow_path != nullptr) { |
| 5262 | __ Bind(slow_path->GetExitLabel()); |
| 5263 | } |
| 5264 | |
| 5265 | break; |
| 5266 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5267 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5268 | case DataType::Type::kInt32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5269 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5270 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5271 | if (value.IsRegister()) { |
| 5272 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 5273 | } else { |
| 5274 | DCHECK(value.IsConstant()) << value; |
| 5275 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5276 | __ movl(address, Immediate(v)); |
| 5277 | } |
| 5278 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5279 | break; |
| 5280 | } |
| 5281 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5282 | case DataType::Type::kInt64: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5283 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5284 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5285 | if (value.IsRegister()) { |
| 5286 | __ movq(address, value.AsRegister<CpuRegister>()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5287 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5288 | } else { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5289 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5290 | Address address_high = |
| 5291 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5292 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5293 | } |
| 5294 | break; |
| 5295 | } |
| 5296 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5297 | case DataType::Type::kFloat32: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5298 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5299 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_4, offset); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5300 | if (value.IsFpuRegister()) { |
| 5301 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5302 | } else { |
| 5303 | DCHECK(value.IsConstant()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5304 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5305 | __ movl(address, Immediate(v)); |
| 5306 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5307 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5308 | break; |
| 5309 | } |
| 5310 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5311 | case DataType::Type::kFloat64: { |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5312 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5313 | Address address = CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5314 | if (value.IsFpuRegister()) { |
| 5315 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5316 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5317 | } else { |
| 5318 | int64_t v = |
| 5319 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5320 | Address address_high = |
| 5321 | CodeGeneratorX86_64::ArrayAddress(array, index, TIMES_8, offset + sizeof(int32_t)); |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5322 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5323 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5324 | break; |
| 5325 | } |
| 5326 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5327 | case DataType::Type::kUint32: |
| 5328 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5329 | case DataType::Type::kVoid: |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5330 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5331 | UNREACHABLE(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5332 | } |
| 5333 | } |
| 5334 | |
| 5335 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5336 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5337 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5338 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5339 | if (!instruction->IsEmittedAtUseSite()) { |
| 5340 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5341 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5345 | if (instruction->IsEmittedAtUseSite()) { |
| 5346 | return; |
| 5347 | } |
| 5348 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5349 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5350 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5351 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5352 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5353 | __ movl(out, Address(obj, offset)); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5354 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5355 | // Mask out most significant bit in case the array is String's array of char. |
| 5356 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5357 | __ shrl(out, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5358 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5362 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5363 | InvokeRuntimeCallingConvention calling_convention; |
| 5364 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5365 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5366 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5367 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5368 | HInstruction* length = instruction->InputAt(1); |
| 5369 | if (!length->IsEmittedAtUseSite()) { |
| 5370 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5371 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5372 | } |
| 5373 | |
| 5374 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5375 | LocationSummary* locations = instruction->GetLocations(); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5376 | Location index_loc = locations->InAt(0); |
| 5377 | Location length_loc = locations->InAt(1); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5378 | SlowPathCode* slow_path = |
| 5379 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86_64(instruction); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5380 | |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5381 | if (length_loc.IsConstant()) { |
| 5382 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5383 | if (index_loc.IsConstant()) { |
| 5384 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5385 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5386 | if (index < 0 || index >= length) { |
| 5387 | codegen_->AddSlowPath(slow_path); |
| 5388 | __ jmp(slow_path->GetEntryLabel()); |
| 5389 | } else { |
| 5390 | // Some optimization after BCE may have generated this, and we should not |
| 5391 | // generate a bounds check if it is a valid range. |
| 5392 | } |
| 5393 | return; |
| 5394 | } |
| 5395 | |
| 5396 | // We have to reverse the jump condition because the length is the constant. |
| 5397 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5398 | __ cmpl(index_reg, Immediate(length)); |
| 5399 | codegen_->AddSlowPath(slow_path); |
| 5400 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5401 | } else { |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5402 | HInstruction* array_length = instruction->InputAt(1); |
| 5403 | if (array_length->IsEmittedAtUseSite()) { |
| 5404 | // Address the length field in the array. |
| 5405 | DCHECK(array_length->IsArrayLength()); |
| 5406 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5407 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5408 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5409 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5410 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for |
| 5411 | // the string compression flag) with the in-memory length and avoid the temporary. |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5412 | CpuRegister length_reg = CpuRegister(TMP); |
| 5413 | __ movl(length_reg, array_len); |
| 5414 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5415 | __ shrl(length_reg, Immediate(1)); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5416 | codegen_->GenerateIntCompare(length_reg, index_loc); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5417 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5418 | // Checking the bound for general case: |
| 5419 | // Array of char or String's array when the compression feature off. |
| 5420 | if (index_loc.IsConstant()) { |
| 5421 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5422 | __ cmpl(array_len, Immediate(value)); |
| 5423 | } else { |
| 5424 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5425 | } |
| 5426 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5427 | } |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5428 | } else { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5429 | codegen_->GenerateIntCompare(length_loc, index_loc); |
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5430 | } |
| 5431 | codegen_->AddSlowPath(slow_path); |
| 5432 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5433 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5434 | } |
| 5435 | |
| 5436 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5437 | CpuRegister card, |
| 5438 | CpuRegister object, |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5439 | CpuRegister value, |
| 5440 | bool value_can_be_null) { |
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5441 | NearLabel is_null; |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5442 | if (value_can_be_null) { |
| 5443 | __ testl(value, value); |
| 5444 | __ j(kEqual, &is_null); |
| 5445 | } |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5446 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5447 | /* no_rip */ true)); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5448 | __ movq(temp, object); |
| 5449 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5450 | __ movb(Address(temp, card, TIMES_1, 0), card); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5451 | if (value_can_be_null) { |
| 5452 | __ Bind(&is_null); |
| 5453 | } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5454 | } |
| 5455 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5456 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5457 | LOG(FATAL) << "Unimplemented"; |
| 5458 | } |
| 5459 | |
| 5460 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 5461 | if (instruction->GetNext()->IsSuspendCheck() && |
| 5462 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 5463 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 5464 | // The back edge will generate the suspend check. |
| 5465 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 5466 | } |
| 5467 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5468 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5469 | } |
| 5470 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5471 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5472 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5473 | instruction, LocationSummary::kCallOnSlowPath); |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 5474 | // In suspend check slow path, usually there are no caller-save registers at all. |
| 5475 | // If SIMD instructions are present, however, we force spilling all live SIMD |
| 5476 | // registers in full width (since the runtime only saves/restores lower part). |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5477 | locations->SetCustomSlowPathCallerSaves( |
| 5478 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5479 | } |
| 5480 | |
| 5481 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5482 | HBasicBlock* block = instruction->GetBlock(); |
| 5483 | if (block->GetLoopInformation() != nullptr) { |
| 5484 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5485 | // The back edge will generate the suspend check. |
| 5486 | return; |
| 5487 | } |
| 5488 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5489 | // The goto will generate the suspend check. |
| 5490 | return; |
| 5491 | } |
| 5492 | GenerateSuspendCheck(instruction, nullptr); |
| 5493 | } |
| 5494 | |
| 5495 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5496 | HBasicBlock* successor) { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5497 | SuspendCheckSlowPathX86_64* slow_path = |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5498 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5499 | if (slow_path == nullptr) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5500 | slow_path = |
| 5501 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86_64(instruction, successor); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5502 | instruction->SetSlowPath(slow_path); |
| 5503 | codegen_->AddSlowPath(slow_path); |
| 5504 | if (successor != nullptr) { |
| 5505 | DCHECK(successor->IsLoopHeader()); |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5506 | } |
| 5507 | } else { |
| 5508 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5509 | } |
| 5510 | |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5511 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5512 | /* no_rip */ true), |
| 5513 | Immediate(0)); |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5514 | if (successor == nullptr) { |
| 5515 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5516 | __ Bind(slow_path->GetReturnLabel()); |
| 5517 | } else { |
| 5518 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5519 | __ jmp(slow_path->GetEntryLabel()); |
| 5520 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5521 | } |
| 5522 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5523 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5524 | return codegen_->GetAssembler(); |
| 5525 | } |
| 5526 | |
| 5527 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5528 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5529 | Location source = move->GetSource(); |
| 5530 | Location destination = move->GetDestination(); |
| 5531 | |
| 5532 | if (source.IsRegister()) { |
| 5533 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5534 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5535 | } else if (destination.IsStackSlot()) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5536 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5537 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5538 | } else { |
| 5539 | DCHECK(destination.IsDoubleStackSlot()); |
| 5540 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5541 | source.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5542 | } |
| 5543 | } else if (source.IsStackSlot()) { |
| 5544 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5545 | __ movl(destination.AsRegister<CpuRegister>(), |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5546 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5547 | } else if (destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5548 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5549 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5550 | } else { |
| 5551 | DCHECK(destination.IsStackSlot()); |
| 5552 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5553 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5554 | } |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5555 | } else if (source.IsDoubleStackSlot()) { |
| 5556 | if (destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5557 | __ movq(destination.AsRegister<CpuRegister>(), |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5558 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5559 | } else if (destination.IsFpuRegister()) { |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5560 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5561 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5562 | } else { |
| Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5563 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5564 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5565 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5566 | } |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5567 | } else if (source.IsSIMDStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5568 | if (destination.IsFpuRegister()) { |
| 5569 | __ movups(destination.AsFpuRegister<XmmRegister>(), |
| 5570 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5571 | } else { |
| 5572 | DCHECK(destination.IsSIMDStackSlot()); |
| 5573 | size_t high = kX86_64WordSize; |
| 5574 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5575 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5576 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex() + high)); |
| 5577 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex() + high), CpuRegister(TMP)); |
| 5578 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5579 | } else if (source.IsConstant()) { |
| 5580 | HConstant* constant = source.GetConstant(); |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5581 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5582 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5583 | if (destination.IsRegister()) { |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5584 | if (value == 0) { |
| 5585 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5586 | } else { |
| 5587 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5588 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5589 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5590 | DCHECK(destination.IsStackSlot()) << destination; |
| Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5591 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5592 | } |
| 5593 | } else if (constant->IsLongConstant()) { |
| 5594 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5595 | if (destination.IsRegister()) { |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5596 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5597 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5598 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5599 | codegen_->Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5600 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5601 | } else if (constant->IsFloatConstant()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5602 | float fp_value = constant->AsFloatConstant()->GetValue(); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5603 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5604 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5605 | codegen_->Load32BitValue(dest, fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5606 | } else { |
| 5607 | DCHECK(destination.IsStackSlot()) << destination; |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5608 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5609 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5610 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5611 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5612 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5613 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5614 | int64_t value = bit_cast<int64_t, double>(fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5615 | if (destination.IsFpuRegister()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5616 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5617 | codegen_->Load64BitValue(dest, fp_value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5618 | } else { |
| 5619 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5620 | codegen_->Store64BitValueToStack(destination, value); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5621 | } |
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5622 | } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5623 | } else if (source.IsFpuRegister()) { |
| 5624 | if (destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5625 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5626 | } else if (destination.IsStackSlot()) { |
| 5627 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5628 | source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5629 | } else if (destination.IsDoubleStackSlot()) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5630 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5631 | source.AsFpuRegister<XmmRegister>()); |
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 5632 | } else { |
| 5633 | DCHECK(destination.IsSIMDStackSlot()); |
| 5634 | __ movups(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 5635 | source.AsFpuRegister<XmmRegister>()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5636 | } |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5637 | } |
| 5638 | } |
| 5639 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5640 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5641 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5642 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5643 | __ movl(reg, CpuRegister(TMP)); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5644 | } |
| 5645 | |
| Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5646 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5647 | __ movq(CpuRegister(TMP), reg1); |
| 5648 | __ movq(reg1, reg2); |
| 5649 | __ movq(reg2, CpuRegister(TMP)); |
| 5650 | } |
| 5651 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5652 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5653 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5654 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5655 | __ movq(reg, CpuRegister(TMP)); |
| 5656 | } |
| 5657 | |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5658 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5659 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5660 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5661 | __ movd(reg, CpuRegister(TMP)); |
| 5662 | } |
| 5663 | |
| 5664 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5665 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5666 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5667 | __ movd(reg, CpuRegister(TMP)); |
| 5668 | } |
| 5669 | |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5670 | void ParallelMoveResolverX86_64::Exchange128(XmmRegister reg, int mem) { |
| 5671 | size_t extra_slot = 2 * kX86_64WordSize; |
| 5672 | __ subq(CpuRegister(RSP), Immediate(extra_slot)); |
| 5673 | __ movups(Address(CpuRegister(RSP), 0), XmmRegister(reg)); |
| 5674 | ExchangeMemory64(0, mem + extra_slot, 2); |
| 5675 | __ movups(XmmRegister(reg), Address(CpuRegister(RSP), 0)); |
| 5676 | __ addq(CpuRegister(RSP), Immediate(extra_slot)); |
| 5677 | } |
| 5678 | |
| 5679 | void ParallelMoveResolverX86_64::ExchangeMemory32(int mem1, int mem2) { |
| 5680 | ScratchRegisterScope ensure_scratch( |
| 5681 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5682 | |
| 5683 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5684 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5685 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5686 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5687 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5688 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5689 | CpuRegister(ensure_scratch.GetRegister())); |
| 5690 | } |
| 5691 | |
| 5692 | void ParallelMoveResolverX86_64::ExchangeMemory64(int mem1, int mem2, int num_of_qwords) { |
| 5693 | ScratchRegisterScope ensure_scratch( |
| 5694 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5695 | |
| 5696 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5697 | |
| 5698 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. |
| 5699 | for (int i = 0; i < num_of_qwords; i++) { |
| 5700 | __ movq(CpuRegister(TMP), |
| 5701 | Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5702 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5703 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5704 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), |
| 5705 | CpuRegister(TMP)); |
| 5706 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5707 | CpuRegister(ensure_scratch.GetRegister())); |
| 5708 | stack_offset += kX86_64WordSize; |
| 5709 | } |
| 5710 | } |
| 5711 | |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5712 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5713 | MoveOperands* move = moves_[index]; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5714 | Location source = move->GetSource(); |
| 5715 | Location destination = move->GetDestination(); |
| 5716 | |
| 5717 | if (source.IsRegister() && destination.IsRegister()) { |
| Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5718 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5719 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5720 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5721 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5722 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5723 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5724 | ExchangeMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5725 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5726 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5727 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5728 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5729 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5730 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 1); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5731 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5732 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5733 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5734 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5735 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5736 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5737 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5738 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5739 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5740 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5741 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5742 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 5743 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { |
| 5744 | ExchangeMemory64(destination.GetStackIndex(), source.GetStackIndex(), 2); |
| 5745 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { |
| 5746 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5747 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { |
| 5748 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5749 | } else { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5750 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
| Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5751 | } |
| 5752 | } |
| 5753 | |
| 5754 | |
| 5755 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5756 | __ pushq(CpuRegister(reg)); |
| 5757 | } |
| 5758 | |
| 5759 | |
| 5760 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5761 | __ popq(CpuRegister(reg)); |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5762 | } |
| 5763 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5764 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5765 | SlowPathCode* slow_path, CpuRegister class_reg) { |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 5766 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| 5767 | const size_t status_byte_offset = |
| 5768 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); |
| 5769 | constexpr uint32_t shifted_initialized_value = |
| 5770 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); |
| 5771 | |
| 5772 | __ cmpb(Address(class_reg, status_byte_offset), Immediate(shifted_initialized_value)); |
| Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 5773 | __ j(kBelow, slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5774 | __ Bind(slow_path->GetExitLabel()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5775 | // No need for memory fence, thanks to the x86-64 memory model. |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5776 | } |
| 5777 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 5778 | void InstructionCodeGeneratorX86_64::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, |
| 5779 | CpuRegister temp) { |
| 5780 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 5781 | uint32_t mask = check->GetBitstringMask(); |
| 5782 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 5783 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 5784 | |
| 5785 | if (mask_bits == 16u) { |
| 5786 | // Compare the bitstring in memory. |
| 5787 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); |
| 5788 | } else { |
| 5789 | // /* uint32_t */ temp = temp->status_ |
| 5790 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); |
| 5791 | // Compare the bitstring bits using SUB. |
| 5792 | __ subl(temp, Immediate(path_to_root)); |
| 5793 | // Shift out bits that do not contribute to the comparison. |
| 5794 | __ shll(temp, Immediate(32u - mask_bits)); |
| 5795 | } |
| 5796 | } |
| 5797 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5798 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5799 | HLoadClass::LoadKind desired_class_load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5800 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 5801 | case HLoadClass::LoadKind::kInvalid: |
| 5802 | LOG(FATAL) << "UNREACHABLE"; |
| 5803 | UNREACHABLE(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5804 | case HLoadClass::LoadKind::kReferrersClass: |
| 5805 | break; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5806 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5807 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5808 | case HLoadClass::LoadKind::kBssEntry: |
| 5809 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5810 | break; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5811 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5812 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5813 | break; |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5814 | case HLoadClass::LoadKind::kBootImageAddress: |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5815 | case HLoadClass::LoadKind::kRuntimeCall: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5816 | break; |
| 5817 | } |
| 5818 | return desired_class_load_kind; |
| 5819 | } |
| 5820 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5821 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5822 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5823 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5824 | // Custom calling convention: RAX serves as both input and output. |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5825 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5826 | cls, |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5827 | Location::RegisterLocation(RAX), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5828 | Location::RegisterLocation(RAX)); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5829 | return; |
| 5830 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5831 | DCHECK(!cls->NeedsAccessCheck()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5832 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5833 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5834 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5835 | ? LocationSummary::kCallOnSlowPath |
| 5836 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5837 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5838 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5839 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5840 | } |
| 5841 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5842 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5843 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5844 | } |
| 5845 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5846 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 5847 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 5848 | // Rely on the type resolution and/or initialization to save everything. |
| 5849 | // Custom calling convention: RAX serves as both input and output. |
| 5850 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5851 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 5852 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 5853 | } else { |
| 5854 | // For non-Baker read barrier we have a temp-clobbering call. |
| 5855 | } |
| 5856 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5857 | } |
| 5858 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5859 | Label* CodeGeneratorX86_64::NewJitRootClassPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5860 | dex::TypeIndex type_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5861 | Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5862 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5863 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5864 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5865 | PatchInfo<Label>* info = &jit_class_patches_.back(); |
| 5866 | return &info->label; |
| 5867 | } |
| 5868 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5869 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 5870 | // move. |
| 5871 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5872 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 5873 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5874 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5875 | return; |
| 5876 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5877 | DCHECK(!cls->NeedsAccessCheck()); |
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5878 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5879 | LocationSummary* locations = cls->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5880 | Location out_loc = locations->Out(); |
| 5881 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5882 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5883 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 5884 | ? kWithoutReadBarrier |
| 5885 | : kCompilerReadBarrierOption; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5886 | bool generate_null_check = false; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 5887 | switch (load_kind) { |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5888 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5889 | DCHECK(!cls->CanCallRuntime()); |
| 5890 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5891 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5892 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5893 | GenerateGcRootFieldLoad( |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5894 | cls, |
| 5895 | out_loc, |
| 5896 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| Roland Levillain | 00468f3 | 2016-10-27 18:02:48 +0100 | [diff] [blame] | 5897 | /* fixup_label */ nullptr, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5898 | read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5899 | break; |
| 5900 | } |
| 5901 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5902 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5903 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5904 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5905 | codegen_->RecordBootImageTypePatch(cls); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5906 | break; |
| 5907 | case HLoadClass::LoadKind::kBootImageAddress: { |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 5908 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5909 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 5910 | reinterpret_cast<uintptr_t>(cls->GetClass().Get())); |
| 5911 | DCHECK_NE(address, 0u); |
| Colin Cross | 0bd9717 | 2017-03-15 16:33:27 -0700 | [diff] [blame] | 5912 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5913 | break; |
| 5914 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5915 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5916 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 5917 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5918 | codegen_->RecordBootImageRelRoPatch(codegen_->GetBootImageOffset(cls)); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 5919 | break; |
| 5920 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 5921 | case HLoadClass::LoadKind::kBssEntry: { |
| 5922 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5923 | /* no_rip */ false); |
| 5924 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); |
| 5925 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 5926 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| 5927 | generate_null_check = true; |
| 5928 | break; |
| 5929 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 5930 | case HLoadClass::LoadKind::kJitTableAddress: { |
| 5931 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5932 | /* no_rip */ true); |
| 5933 | Label* fixup_label = |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 5934 | codegen_->NewJitRootClassPatch(cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5935 | // /* GcRoot<mirror::Class> */ out = *address |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 5936 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5937 | break; |
| 5938 | } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5939 | default: |
| 5940 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5941 | UNREACHABLE(); |
| 5942 | } |
| 5943 | |
| 5944 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5945 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5946 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64( |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5947 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5948 | codegen_->AddSlowPath(slow_path); |
| 5949 | if (generate_null_check) { |
| 5950 | __ testl(out, out); |
| 5951 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5952 | } |
| 5953 | if (cls->MustGenerateClinitCheck()) { |
| 5954 | GenerateClassInitializationCheck(slow_path, out); |
| 5955 | } else { |
| 5956 | __ Bind(slow_path->GetExitLabel()); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5957 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5958 | } |
| 5959 | } |
| 5960 | |
| 5961 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5962 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5963 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5964 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5965 | if (check->HasUses()) { |
| 5966 | locations->SetOut(Location::SameAsFirstInput()); |
| 5967 | } |
| 5968 | } |
| 5969 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 5970 | void LocationsBuilderX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5971 | // Custom calling convention: RAX serves as both input and output. |
| 5972 | Location location = Location::RegisterLocation(RAX); |
| 5973 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 5974 | } |
| 5975 | |
| 5976 | void InstructionCodeGeneratorX86_64::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 5977 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 5978 | } |
| 5979 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 5980 | void LocationsBuilderX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5981 | // Custom calling convention: RAX serves as both input and output. |
| 5982 | Location location = Location::RegisterLocation(RAX); |
| 5983 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 5984 | } |
| 5985 | |
| 5986 | void InstructionCodeGeneratorX86_64::VisitLoadMethodType(HLoadMethodType* load) { |
| 5987 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 5988 | } |
| 5989 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5990 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5991 | // We assume the class to not be null. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5992 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86_64( |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5993 | check->GetLoadClass(), check, check->GetDexPc(), true); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5994 | codegen_->AddSlowPath(slow_path); |
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5995 | GenerateClassInitializationCheck(slow_path, |
| 5996 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5997 | } |
| 5998 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5999 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 6000 | HLoadString::LoadKind desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6001 | switch (desired_string_load_kind) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6002 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6003 | case HLoadString::LoadKind::kBootImageRelRo: |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6004 | case HLoadString::LoadKind::kBssEntry: |
| Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6005 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6006 | break; |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6007 | case HLoadString::LoadKind::kJitTableAddress: |
| 6008 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 6009 | break; |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6010 | case HLoadString::LoadKind::kBootImageAddress: |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6011 | case HLoadString::LoadKind::kRuntimeCall: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6012 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6013 | } |
| 6014 | return desired_string_load_kind; |
| 6015 | } |
| 6016 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6017 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6018 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6019 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6020 | if (load->GetLoadKind() == HLoadString::LoadKind::kRuntimeCall) { |
| Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6021 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 6022 | } else { |
| 6023 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6024 | if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) { |
| 6025 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6026 | // Rely on the pResolveString to save everything. |
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6027 | // Custom calling convention: RAX serves as both input and output. |
| 6028 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6029 | caller_saves.Add(Location::RegisterLocation(RAX)); |
| 6030 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| 6031 | } else { |
| 6032 | // For non-Baker read barrier we have a temp-clobbering call. |
| 6033 | } |
| 6034 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6035 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6036 | } |
| 6037 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6038 | Label* CodeGeneratorX86_64::NewJitRootStringPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6039 | dex::StringIndex string_index, |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6040 | Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6041 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6042 | // Add a patch entry and return the label. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6043 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6044 | PatchInfo<Label>* info = &jit_string_patches_.back(); |
| 6045 | return &info->label; |
| 6046 | } |
| 6047 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6048 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 6049 | // move. |
| 6050 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6051 | LocationSummary* locations = load->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6052 | Location out_loc = locations->Out(); |
| 6053 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6054 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6055 | switch (load->GetLoadKind()) { |
| 6056 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6057 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6058 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6059 | codegen_->RecordBootImageStringPatch(load); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6060 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6061 | } |
| 6062 | case HLoadString::LoadKind::kBootImageAddress: { |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6063 | uint32_t address = dchecked_integral_cast<uint32_t>( |
| 6064 | reinterpret_cast<uintptr_t>(load->GetString().Get())); |
| 6065 | DCHECK_NE(address, 0u); |
| Colin Cross | 0bd9717 | 2017-03-15 16:33:27 -0700 | [diff] [blame] | 6066 | __ movl(out, Immediate(static_cast<int32_t>(address))); // Zero-extended. |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6067 | return; |
| 6068 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6069 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6070 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 6071 | __ movl(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6072 | codegen_->RecordBootImageRelRoPatch(codegen_->GetBootImageOffset(load)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6073 | return; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6074 | } |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6075 | case HLoadString::LoadKind::kBssEntry: { |
| 6076 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 6077 | /* no_rip */ false); |
| 6078 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 6079 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6080 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6081 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86_64(load); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6082 | codegen_->AddSlowPath(slow_path); |
| 6083 | __ testl(out, out); |
| 6084 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6085 | __ Bind(slow_path->GetExitLabel()); |
| 6086 | return; |
| 6087 | } |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6088 | case HLoadString::LoadKind::kJitTableAddress: { |
| 6089 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 6090 | /* no_rip */ true); |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6091 | Label* fixup_label = codegen_->NewJitRootStringPatch( |
| 6092 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6093 | // /* GcRoot<mirror::String> */ out = *address |
| 6094 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); |
| 6095 | return; |
| 6096 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6097 | default: |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6098 | break; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6099 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6100 | |
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6101 | // 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] | 6102 | // Custom calling convention: RAX serves as both input and output. |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6103 | __ movl(CpuRegister(RAX), Immediate(load->GetStringIndex().index_)); |
| Christina Wadsworth | abb341b | 2016-08-31 16:29:44 -0700 | [diff] [blame] | 6104 | codegen_->InvokeRuntime(kQuickResolveString, |
| 6105 | load, |
| 6106 | load->GetDexPc()); |
| 6107 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6108 | } |
| 6109 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6110 | static Address GetExceptionTlsAddress() { |
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6111 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6112 | /* no_rip */ true); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6113 | } |
| 6114 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6115 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 6116 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6117 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6118 | locations->SetOut(Location::RequiresRegister()); |
| 6119 | } |
| 6120 | |
| 6121 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6122 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 6123 | } |
| 6124 | |
| 6125 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6126 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6130 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6131 | } |
| 6132 | |
| 6133 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6134 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6135 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6136 | InvokeRuntimeCallingConvention calling_convention; |
| 6137 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6138 | } |
| 6139 | |
| 6140 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6141 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6142 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6143 | } |
| 6144 | |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6145 | // Temp is used for read barrier. |
| 6146 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 6147 | if (kEmitCompilerReadBarrier && |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6148 | !kUseBakerReadBarrier && |
| 6149 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6150 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6151 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 6152 | return 1; |
| 6153 | } |
| 6154 | return 0; |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6155 | } |
| 6156 | |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6157 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current |
| 6158 | // interface pointer, the current interface is compared in memory. |
| 6159 | // The other checks have one temp for loading the object's class. |
| 6160 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 6161 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6162 | return 2; |
| 6163 | } |
| 6164 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| Nicolas Geoffray | 53b07bd | 2016-11-05 15:09:19 +0000 | [diff] [blame] | 6165 | } |
| 6166 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6167 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6168 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6169 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6170 | bool baker_read_barrier_slow_path = false; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6171 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6172 | case TypeCheckKind::kExactCheck: |
| 6173 | case TypeCheckKind::kAbstractClassCheck: |
| 6174 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6175 | case TypeCheckKind::kArrayObjectCheck: { |
| 6176 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 6177 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 6178 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6179 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6180 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6181 | case TypeCheckKind::kArrayCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6182 | case TypeCheckKind::kUnresolvedCheck: |
| 6183 | case TypeCheckKind::kInterfaceCheck: |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6184 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6185 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6186 | case TypeCheckKind::kBitstringCheck: |
| 6187 | break; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6188 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6189 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6190 | LocationSummary* locations = |
| 6191 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6192 | if (baker_read_barrier_slow_path) { |
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6193 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6194 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6195 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6196 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6197 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6198 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6199 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 6200 | } else { |
| 6201 | locations->SetInAt(1, Location::Any()); |
| 6202 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6203 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 6204 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6205 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6206 | } |
| 6207 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6208 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6209 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6210 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6211 | Location obj_loc = locations->InAt(0); |
| 6212 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6213 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6214 | Location out_loc = locations->Out(); |
| 6215 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6216 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 6217 | DCHECK_LE(num_temps, 1u); |
| 6218 | Location maybe_temp_loc = (num_temps >= 1u) ? locations->GetTemp(0) : Location::NoLocation(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6219 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6220 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6221 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6222 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6223 | SlowPathCode* slow_path = nullptr; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6224 | NearLabel done, zero; |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6225 | |
| 6226 | // Return 0 if `obj` is null. |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6227 | // Avoid null check if we know obj is not null. |
| 6228 | if (instruction->MustDoNullCheck()) { |
| 6229 | __ testl(obj, obj); |
| 6230 | __ j(kEqual, &zero); |
| 6231 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6232 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6233 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6234 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6235 | ReadBarrierOption read_barrier_option = |
| 6236 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6237 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6238 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6239 | out_loc, |
| 6240 | obj_loc, |
| 6241 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6242 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6243 | if (cls.IsRegister()) { |
| 6244 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6245 | } else { |
| 6246 | DCHECK(cls.IsStackSlot()) << cls; |
| 6247 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6248 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6249 | if (zero.IsLinked()) { |
| 6250 | // Classes must be equal for the instanceof to succeed. |
| 6251 | __ j(kNotEqual, &zero); |
| 6252 | __ movl(out, Immediate(1)); |
| 6253 | __ jmp(&done); |
| 6254 | } else { |
| 6255 | __ setcc(kEqual, out); |
| 6256 | // setcc only sets the low byte. |
| 6257 | __ andl(out, Immediate(1)); |
| 6258 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6259 | break; |
| 6260 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6261 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6262 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6263 | ReadBarrierOption read_barrier_option = |
| 6264 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6265 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6266 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6267 | out_loc, |
| 6268 | obj_loc, |
| 6269 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6270 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6271 | // If the class is abstract, we eagerly fetch the super class of the |
| 6272 | // object to avoid doing a comparison we know will fail. |
| 6273 | NearLabel loop, success; |
| 6274 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6275 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6276 | GenerateReferenceLoadOneRegister(instruction, |
| 6277 | out_loc, |
| 6278 | super_offset, |
| 6279 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6280 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6281 | __ testl(out, out); |
| 6282 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6283 | __ j(kEqual, &done); |
| 6284 | if (cls.IsRegister()) { |
| 6285 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6286 | } else { |
| 6287 | DCHECK(cls.IsStackSlot()) << cls; |
| 6288 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6289 | } |
| 6290 | __ j(kNotEqual, &loop); |
| 6291 | __ movl(out, Immediate(1)); |
| 6292 | if (zero.IsLinked()) { |
| 6293 | __ jmp(&done); |
| 6294 | } |
| 6295 | break; |
| 6296 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6297 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6298 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6299 | ReadBarrierOption read_barrier_option = |
| 6300 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6301 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6302 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6303 | out_loc, |
| 6304 | obj_loc, |
| 6305 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6306 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6307 | // Walk over the class hierarchy to find a match. |
| 6308 | NearLabel loop, success; |
| 6309 | __ Bind(&loop); |
| 6310 | if (cls.IsRegister()) { |
| 6311 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6312 | } else { |
| 6313 | DCHECK(cls.IsStackSlot()) << cls; |
| 6314 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6315 | } |
| 6316 | __ j(kEqual, &success); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6317 | // /* HeapReference<Class> */ out = out->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6318 | GenerateReferenceLoadOneRegister(instruction, |
| 6319 | out_loc, |
| 6320 | super_offset, |
| 6321 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6322 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6323 | __ testl(out, out); |
| 6324 | __ j(kNotEqual, &loop); |
| 6325 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6326 | __ jmp(&done); |
| 6327 | __ Bind(&success); |
| 6328 | __ movl(out, Immediate(1)); |
| 6329 | if (zero.IsLinked()) { |
| 6330 | __ jmp(&done); |
| 6331 | } |
| 6332 | break; |
| 6333 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6334 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6335 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6336 | ReadBarrierOption read_barrier_option = |
| 6337 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6338 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6339 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6340 | out_loc, |
| 6341 | obj_loc, |
| 6342 | class_offset, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6343 | read_barrier_option); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6344 | // Do an exact check. |
| 6345 | NearLabel exact_check; |
| 6346 | if (cls.IsRegister()) { |
| 6347 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6348 | } else { |
| 6349 | DCHECK(cls.IsStackSlot()) << cls; |
| 6350 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6351 | } |
| 6352 | __ j(kEqual, &exact_check); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6353 | // 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] | 6354 | // /* HeapReference<Class> */ out = out->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6355 | GenerateReferenceLoadOneRegister(instruction, |
| 6356 | out_loc, |
| 6357 | component_offset, |
| 6358 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6359 | read_barrier_option); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6360 | __ testl(out, out); |
| 6361 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6362 | __ j(kEqual, &done); |
| 6363 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6364 | __ j(kNotEqual, &zero); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6365 | __ Bind(&exact_check); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6366 | __ movl(out, Immediate(1)); |
| 6367 | __ jmp(&done); |
| 6368 | break; |
| 6369 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6370 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6371 | case TypeCheckKind::kArrayCheck: { |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6372 | // No read barrier since the slow path will retry upon failure. |
| 6373 | // /* HeapReference<Class> */ out = obj->klass_ |
| 6374 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6375 | out_loc, |
| 6376 | obj_loc, |
| 6377 | class_offset, |
| 6378 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6379 | if (cls.IsRegister()) { |
| 6380 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 6381 | } else { |
| 6382 | DCHECK(cls.IsStackSlot()) << cls; |
| 6383 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6384 | } |
| 6385 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6386 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6387 | instruction, /* is_fatal */ false); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6388 | codegen_->AddSlowPath(slow_path); |
| 6389 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6390 | __ movl(out, Immediate(1)); |
| 6391 | if (zero.IsLinked()) { |
| 6392 | __ jmp(&done); |
| 6393 | } |
| 6394 | break; |
| 6395 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6396 | |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6397 | case TypeCheckKind::kUnresolvedCheck: |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6398 | case TypeCheckKind::kInterfaceCheck: { |
| 6399 | // 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] | 6400 | // into the slow path for the unresolved and interface check |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6401 | // cases. |
| 6402 | // |
| 6403 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6404 | // entry point without resorting to a type checking slow path |
| 6405 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6406 | // require to assign fixed registers for the inputs of this |
| 6407 | // HInstanceOf instruction (following the runtime calling |
| 6408 | // convention), which might be cluttered by the potential first |
| 6409 | // read barrier emission at the beginning of this method. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6410 | // |
| 6411 | // TODO: Introduce a new runtime entry point taking the object |
| 6412 | // to test (instead of its class) as argument, and let it deal |
| 6413 | // with the read barrier issues. This will let us refactor this |
| 6414 | // case of the `switch` code as it was previously (with a direct |
| 6415 | // call to the runtime not using a type checking slow path). |
| 6416 | // This should also be beneficial for the other cases above. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6417 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6418 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6419 | instruction, /* is_fatal */ false); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6420 | codegen_->AddSlowPath(slow_path); |
| 6421 | __ jmp(slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6422 | if (zero.IsLinked()) { |
| 6423 | __ jmp(&done); |
| 6424 | } |
| 6425 | break; |
| 6426 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6427 | |
| 6428 | case TypeCheckKind::kBitstringCheck: { |
| 6429 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6430 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6431 | out_loc, |
| 6432 | obj_loc, |
| 6433 | class_offset, |
| 6434 | kWithoutReadBarrier); |
| 6435 | |
| 6436 | GenerateBitstringTypeCheckCompare(instruction, out); |
| 6437 | if (zero.IsLinked()) { |
| 6438 | __ j(kNotEqual, &zero); |
| 6439 | __ movl(out, Immediate(1)); |
| 6440 | __ jmp(&done); |
| 6441 | } else { |
| 6442 | __ setcc(kEqual, out); |
| 6443 | // setcc only sets the low byte. |
| 6444 | __ andl(out, Immediate(1)); |
| 6445 | } |
| 6446 | break; |
| 6447 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6448 | } |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6449 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6450 | if (zero.IsLinked()) { |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6451 | __ Bind(&zero); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6452 | __ xorl(out, out); |
| 6453 | } |
| 6454 | |
| 6455 | if (done.IsLinked()) { |
| 6456 | __ Bind(&done); |
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6457 | } |
| 6458 | |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6459 | if (slow_path != nullptr) { |
| 6460 | __ Bind(slow_path->GetExitLabel()); |
| 6461 | } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6462 | } |
| 6463 | |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6464 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| Andreas Gampe | b5f3d81 | 2016-11-04 19:25:20 -0700 | [diff] [blame] | 6465 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6466 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6467 | LocationSummary* locations = |
| 6468 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6469 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6470 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 6471 | // Require a register for the interface check since there is a loop that compares the class to |
| 6472 | // a memory address. |
| 6473 | locations->SetInAt(1, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6474 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 6475 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 6476 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 6477 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6478 | } else { |
| 6479 | locations->SetInAt(1, Location::Any()); |
| 6480 | } |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6481 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathX86. |
| 6482 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6483 | } |
| 6484 | |
| 6485 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6486 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6487 | LocationSummary* locations = instruction->GetLocations(); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6488 | Location obj_loc = locations->InAt(0); |
| 6489 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6490 | Location cls = locations->InAt(1); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6491 | Location temp_loc = locations->GetTemp(0); |
| 6492 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6493 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 6494 | DCHECK_GE(num_temps, 1u); |
| 6495 | DCHECK_LE(num_temps, 2u); |
| 6496 | Location maybe_temp2_loc = (num_temps >= 2u) ? locations->GetTemp(1) : Location::NoLocation(); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6497 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6498 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6499 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6500 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 6501 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 6502 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6503 | const uint32_t object_array_data_offset = |
| 6504 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6505 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6506 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6507 | SlowPathCode* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6508 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86_64( |
| 6509 | instruction, is_type_check_slow_path_fatal); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6510 | codegen_->AddSlowPath(type_check_slow_path); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6511 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6512 | |
| 6513 | NearLabel done; |
| 6514 | // Avoid null check if we know obj is not null. |
| 6515 | if (instruction->MustDoNullCheck()) { |
| 6516 | __ testl(obj, obj); |
| 6517 | __ j(kEqual, &done); |
| 6518 | } |
| 6519 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6520 | switch (type_check_kind) { |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6521 | case TypeCheckKind::kExactCheck: |
| 6522 | case TypeCheckKind::kArrayCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6523 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6524 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6525 | temp_loc, |
| 6526 | obj_loc, |
| 6527 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6528 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6529 | if (cls.IsRegister()) { |
| 6530 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6531 | } else { |
| 6532 | DCHECK(cls.IsStackSlot()) << cls; |
| 6533 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6534 | } |
| 6535 | // Jump to slow path for throwing the exception or doing a |
| 6536 | // more involved array check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6537 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6538 | break; |
| 6539 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6540 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6541 | case TypeCheckKind::kAbstractClassCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6542 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6543 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6544 | temp_loc, |
| 6545 | obj_loc, |
| 6546 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6547 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6548 | // If the class is abstract, we eagerly fetch the super class of the |
| 6549 | // object to avoid doing a comparison we know will fail. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6550 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6551 | __ Bind(&loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6552 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6553 | GenerateReferenceLoadOneRegister(instruction, |
| 6554 | temp_loc, |
| 6555 | super_offset, |
| 6556 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6557 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6558 | |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6559 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 6560 | // exception. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6561 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6562 | // Otherwise, compare the classes. |
| 6563 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6564 | if (cls.IsRegister()) { |
| 6565 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6566 | } else { |
| 6567 | DCHECK(cls.IsStackSlot()) << cls; |
| 6568 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6569 | } |
| 6570 | __ j(kNotEqual, &loop); |
| 6571 | break; |
| 6572 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6573 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6574 | case TypeCheckKind::kClassHierarchyCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6575 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6576 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6577 | temp_loc, |
| 6578 | obj_loc, |
| 6579 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6580 | kWithoutReadBarrier); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6581 | // Walk over the class hierarchy to find a match. |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6582 | NearLabel loop; |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6583 | __ Bind(&loop); |
| 6584 | if (cls.IsRegister()) { |
| 6585 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6586 | } else { |
| 6587 | DCHECK(cls.IsStackSlot()) << cls; |
| 6588 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6589 | } |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6590 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6591 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6592 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6593 | GenerateReferenceLoadOneRegister(instruction, |
| 6594 | temp_loc, |
| 6595 | super_offset, |
| 6596 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6597 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6598 | |
| 6599 | // If the class reference currently in `temp` is not null, jump |
| 6600 | // back at the beginning of the loop. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6601 | __ testl(temp, temp); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6602 | __ j(kNotZero, &loop); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6603 | // Otherwise, jump to the slow path to throw the exception. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6604 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6605 | break; |
| 6606 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6607 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6608 | case TypeCheckKind::kArrayObjectCheck: { |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6609 | // /* HeapReference<Class> */ temp = obj->klass_ |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6610 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6611 | temp_loc, |
| 6612 | obj_loc, |
| 6613 | class_offset, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6614 | kWithoutReadBarrier); |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6615 | // Do an exact check. |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6616 | NearLabel check_non_primitive_component_type; |
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6617 | if (cls.IsRegister()) { |
| 6618 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6619 | } else { |
| 6620 | DCHECK(cls.IsStackSlot()) << cls; |
| 6621 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6622 | } |
| 6623 | __ j(kEqual, &done); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6624 | |
| 6625 | // 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] | 6626 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6627 | GenerateReferenceLoadOneRegister(instruction, |
| 6628 | temp_loc, |
| 6629 | component_offset, |
| 6630 | maybe_temp2_loc, |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6631 | kWithoutReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6632 | |
| 6633 | // If the component type is not null (i.e. the object is indeed |
| 6634 | // an array), jump to label `check_non_primitive_component_type` |
| 6635 | // to further check that this component type is not a primitive |
| 6636 | // type. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6637 | __ testl(temp, temp); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6638 | // Otherwise, jump to the slow path to throw the exception. |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6639 | __ j(kZero, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6640 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 6641 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6642 | break; |
| 6643 | } |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6644 | |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6645 | case TypeCheckKind::kUnresolvedCheck: { |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6646 | // 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] | 6647 | // |
| 6648 | // We cannot directly call the CheckCast runtime entry point |
| 6649 | // without resorting to a type checking slow path here (i.e. by |
| 6650 | // calling InvokeRuntime directly), as it would require to |
| 6651 | // assign fixed registers for the inputs of this HInstanceOf |
| 6652 | // instruction (following the runtime calling convention), which |
| 6653 | // might be cluttered by the potential first read barrier |
| 6654 | // emission at the beginning of this method. |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6655 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6656 | break; |
| 6657 | } |
| 6658 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6659 | case TypeCheckKind::kInterfaceCheck: { |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6660 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. |
| 6661 | // We can not get false positives by doing this. |
| 6662 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6663 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6664 | temp_loc, |
| 6665 | obj_loc, |
| 6666 | class_offset, |
| 6667 | kWithoutReadBarrier); |
| Mathieu Chartier | cdba73b | 2016-11-03 19:23:06 -0700 | [diff] [blame] | 6668 | |
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6669 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 6670 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6671 | temp_loc, |
| 6672 | temp_loc, |
| 6673 | iftable_offset, |
| 6674 | kWithoutReadBarrier); |
| 6675 | // Iftable is never null. |
| 6676 | __ movl(maybe_temp2_loc.AsRegister<CpuRegister>(), Address(temp, array_length_offset)); |
| 6677 | // Maybe poison the `cls` for direct comparison with memory. |
| 6678 | __ MaybePoisonHeapReference(cls.AsRegister<CpuRegister>()); |
| 6679 | // Loop through the iftable and check if any class matches. |
| 6680 | NearLabel start_loop; |
| 6681 | __ Bind(&start_loop); |
| 6682 | // Need to subtract first to handle the empty array case. |
| 6683 | __ subl(maybe_temp2_loc.AsRegister<CpuRegister>(), Immediate(2)); |
| 6684 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); |
| 6685 | // Go to next interface if the classes do not match. |
| 6686 | __ cmpl(cls.AsRegister<CpuRegister>(), |
| 6687 | CodeGeneratorX86_64::ArrayAddress(temp, |
| 6688 | maybe_temp2_loc, |
| 6689 | TIMES_4, |
| 6690 | object_array_data_offset)); |
| 6691 | __ j(kNotEqual, &start_loop); // Return if same class. |
| 6692 | // If `cls` was poisoned above, unpoison it. |
| 6693 | __ MaybeUnpoisonHeapReference(cls.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6694 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6695 | } |
| 6696 | |
| 6697 | case TypeCheckKind::kBitstringCheck: { |
| 6698 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6699 | GenerateReferenceLoadTwoRegisters(instruction, |
| 6700 | temp_loc, |
| 6701 | obj_loc, |
| 6702 | class_offset, |
| 6703 | kWithoutReadBarrier); |
| 6704 | |
| 6705 | GenerateBitstringTypeCheckCompare(instruction, temp); |
| 6706 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
| 6707 | break; |
| 6708 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6709 | } |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6710 | |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6711 | if (done.IsLinked()) { |
| 6712 | __ Bind(&done); |
| 6713 | } |
| 6714 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6715 | __ Bind(type_check_slow_path->GetExitLabel()); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6716 | } |
| 6717 | |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6718 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6719 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6720 | instruction, LocationSummary::kCallOnMainOnly); |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6721 | InvokeRuntimeCallingConvention calling_convention; |
| 6722 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6723 | } |
| 6724 | |
| 6725 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6726 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6727 | instruction, |
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6728 | instruction->GetDexPc()); |
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6729 | if (instruction->IsEnter()) { |
| 6730 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6731 | } else { |
| 6732 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6733 | } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6734 | } |
| 6735 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6736 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6737 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6738 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6739 | |
| 6740 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6741 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6742 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6743 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 6744 | || instruction->GetResultType() == DataType::Type::kInt64); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6745 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6746 | locations->SetInAt(1, Location::Any()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6747 | locations->SetOut(Location::SameAsFirstInput()); |
| 6748 | } |
| 6749 | |
| 6750 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6751 | HandleBitwiseOperation(instruction); |
| 6752 | } |
| 6753 | |
| 6754 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6755 | HandleBitwiseOperation(instruction); |
| 6756 | } |
| 6757 | |
| 6758 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6759 | HandleBitwiseOperation(instruction); |
| 6760 | } |
| 6761 | |
| 6762 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6763 | LocationSummary* locations = instruction->GetLocations(); |
| 6764 | Location first = locations->InAt(0); |
| 6765 | Location second = locations->InAt(1); |
| 6766 | DCHECK(first.Equals(locations->Out())); |
| 6767 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6768 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6769 | if (second.IsRegister()) { |
| 6770 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6771 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6772 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6773 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6774 | } else { |
| 6775 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6776 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6777 | } |
| 6778 | } else if (second.IsConstant()) { |
| 6779 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6780 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6781 | __ andl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6782 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6783 | __ orl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6784 | } else { |
| 6785 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6786 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6787 | } |
| 6788 | } else { |
| 6789 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6790 | if (instruction->IsAnd()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6791 | __ andl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6792 | } else if (instruction->IsOr()) { |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6793 | __ orl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6794 | } else { |
| 6795 | DCHECK(instruction->IsXor()); |
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6796 | __ xorl(first.AsRegister<CpuRegister>(), address); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6797 | } |
| 6798 | } |
| 6799 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6800 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6801 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6802 | bool second_is_constant = false; |
| 6803 | int64_t value = 0; |
| 6804 | if (second.IsConstant()) { |
| 6805 | second_is_constant = true; |
| 6806 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6807 | } |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6808 | bool is_int32_value = IsInt<32>(value); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6809 | |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6810 | if (instruction->IsAnd()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6811 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6812 | if (is_int32_value) { |
| 6813 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6814 | } else { |
| 6815 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6816 | } |
| 6817 | } else if (second.IsDoubleStackSlot()) { |
| 6818 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6819 | } else { |
| 6820 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6821 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6822 | } else if (instruction->IsOr()) { |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6823 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6824 | if (is_int32_value) { |
| 6825 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6826 | } else { |
| 6827 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6828 | } |
| 6829 | } else if (second.IsDoubleStackSlot()) { |
| 6830 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6831 | } else { |
| 6832 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6833 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6834 | } else { |
| 6835 | DCHECK(instruction->IsXor()); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6836 | if (second_is_constant) { |
| Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6837 | if (is_int32_value) { |
| 6838 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6839 | } else { |
| 6840 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6841 | } |
| 6842 | } else if (second.IsDoubleStackSlot()) { |
| 6843 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6844 | } else { |
| 6845 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6846 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6847 | } |
| 6848 | } |
| 6849 | } |
| 6850 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6851 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister( |
| 6852 | HInstruction* instruction, |
| 6853 | Location out, |
| 6854 | uint32_t offset, |
| 6855 | Location maybe_temp, |
| 6856 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6857 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6858 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6859 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6860 | if (kUseBakerReadBarrier) { |
| 6861 | // Load with fast path based Baker's read barrier. |
| 6862 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6863 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6864 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6865 | } else { |
| 6866 | // Load with slow path based read barrier. |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6867 | // Save the value of `out` into `maybe_temp` before overwriting it |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6868 | // in the following move operation, as we will need it for the |
| 6869 | // read barrier below. |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6870 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6871 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6872 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6873 | __ movl(out_reg, Address(out_reg, offset)); |
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6874 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6875 | } |
| 6876 | } else { |
| 6877 | // Plain load with no read barrier. |
| 6878 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6879 | __ movl(out_reg, Address(out_reg, offset)); |
| 6880 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6881 | } |
| 6882 | } |
| 6883 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6884 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters( |
| 6885 | HInstruction* instruction, |
| 6886 | Location out, |
| 6887 | Location obj, |
| 6888 | uint32_t offset, |
| 6889 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6890 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6891 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6892 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 6893 | CHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6894 | if (kUseBakerReadBarrier) { |
| 6895 | // Load with fast path based Baker's read barrier. |
| 6896 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6897 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6898 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6899 | } else { |
| 6900 | // Load with slow path based read barrier. |
| 6901 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6902 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6903 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6904 | } |
| 6905 | } else { |
| 6906 | // Plain load with no read barrier. |
| 6907 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6908 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6909 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6910 | } |
| 6911 | } |
| 6912 | |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6913 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad( |
| 6914 | HInstruction* instruction, |
| 6915 | Location root, |
| 6916 | const Address& address, |
| 6917 | Label* fixup_label, |
| 6918 | ReadBarrierOption read_barrier_option) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6919 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6920 | if (read_barrier_option == kWithReadBarrier) { |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6921 | DCHECK(kEmitCompilerReadBarrier); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6922 | if (kUseBakerReadBarrier) { |
| 6923 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6924 | // Baker's read barrier are used: |
| 6925 | // |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6926 | // root = obj.field; |
| 6927 | // temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() |
| 6928 | // if (temp != null) { |
| 6929 | // root = temp(root) |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6930 | // } |
| 6931 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6932 | // /* GcRoot<mirror::Object> */ root = *address |
| 6933 | __ movl(root_reg, address); |
| 6934 | if (fixup_label != nullptr) { |
| 6935 | __ Bind(fixup_label); |
| 6936 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6937 | static_assert( |
| 6938 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6939 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6940 | "have different sizes."); |
| 6941 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6942 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6943 | "have different sizes."); |
| 6944 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6945 | // Slow path marking the GC root `root`. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6946 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 6947 | instruction, root, /* unpoison_ref_before_marking */ false); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6948 | codegen_->AddSlowPath(slow_path); |
| 6949 | |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6950 | // Test the `Thread::Current()->pReadBarrierMarkReg ## root.reg()` entrypoint. |
| 6951 | const int32_t entry_point_offset = |
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 6952 | Thread::ReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(root.reg()); |
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 6953 | __ gs()->cmpl(Address::Absolute(entry_point_offset, /* no_rip */ true), Immediate(0)); |
| 6954 | // The entrypoint is null when the GC is not marking. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6955 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6956 | __ Bind(slow_path->GetExitLabel()); |
| 6957 | } else { |
| 6958 | // GC root loaded through a slow path for read barriers other |
| 6959 | // than Baker's. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6960 | // /* GcRoot<mirror::Object>* */ root = address |
| 6961 | __ leaq(root_reg, address); |
| 6962 | if (fixup_label != nullptr) { |
| 6963 | __ Bind(fixup_label); |
| 6964 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6965 | // /* mirror::Object* */ root = root->Read() |
| 6966 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6967 | } |
| 6968 | } else { |
| 6969 | // Plain GC root load with no read barrier. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6970 | // /* GcRoot<mirror::Object> */ root = *address |
| 6971 | __ movl(root_reg, address); |
| 6972 | if (fixup_label != nullptr) { |
| 6973 | __ Bind(fixup_label); |
| 6974 | } |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6975 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6976 | // do not have to unpoison `root_reg` here. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6977 | } |
| 6978 | } |
| 6979 | |
| 6980 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6981 | Location ref, |
| 6982 | CpuRegister obj, |
| 6983 | uint32_t offset, |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6984 | bool needs_null_check) { |
| 6985 | DCHECK(kEmitCompilerReadBarrier); |
| 6986 | DCHECK(kUseBakerReadBarrier); |
| 6987 | |
| 6988 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6989 | Address src(obj, offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6990 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6991 | } |
| 6992 | |
| 6993 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6994 | Location ref, |
| 6995 | CpuRegister obj, |
| 6996 | uint32_t data_offset, |
| 6997 | Location index, |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6998 | bool needs_null_check) { |
| 6999 | DCHECK(kEmitCompilerReadBarrier); |
| 7000 | DCHECK(kUseBakerReadBarrier); |
| 7001 | |
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7002 | static_assert( |
| 7003 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7004 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7005 | // /* HeapReference<Object> */ ref = |
| 7006 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7007 | Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_4, data_offset); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7008 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7009 | } |
| 7010 | |
| 7011 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7012 | Location ref, |
| 7013 | CpuRegister obj, |
| 7014 | const Address& src, |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7015 | bool needs_null_check, |
| 7016 | bool always_update_field, |
| 7017 | CpuRegister* temp1, |
| 7018 | CpuRegister* temp2) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7019 | DCHECK(kEmitCompilerReadBarrier); |
| 7020 | DCHECK(kUseBakerReadBarrier); |
| 7021 | |
| 7022 | // In slow path based read barriers, the read barrier call is |
| 7023 | // inserted after the original load. However, in fast path based |
| 7024 | // Baker's read barriers, we need to perform the load of |
| 7025 | // mirror::Object::monitor_ *before* the original reference load. |
| 7026 | // This load-load ordering is required by the read barrier. |
| 7027 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7028 | // |
| 7029 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7030 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7031 | // HeapReference<Object> ref = *src; // Original reference load. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7032 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7033 | // if (is_gray) { |
| 7034 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7035 | // } |
| 7036 | // |
| 7037 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7038 | // slightly more complex as: |
| 7039 | // - it implements the load-load fence using a data dependency on |
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7040 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7041 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 7042 | // 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] | 7043 | // - it performs additional checks that we do not do here for |
| 7044 | // performance reasons. |
| 7045 | |
| 7046 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7047 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7048 | |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7049 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7050 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 7051 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7052 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 7053 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 7054 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 7055 | |
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7056 | // if (rb_state == ReadBarrier::GrayState()) |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7057 | // ref = ReadBarrier::Mark(ref); |
| 7058 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 7059 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7060 | if (needs_null_check) { |
| 7061 | MaybeRecordImplicitNullCheck(instruction); |
| 7062 | } |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7063 | |
| 7064 | // Load fence to prevent load-load reordering. |
| 7065 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 7066 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7067 | |
| 7068 | // The actual reference load. |
| 7069 | // /* HeapReference<Object> */ ref = *src |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7070 | __ movl(ref_reg, src); // Flags are unaffected. |
| 7071 | |
| 7072 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 7073 | // Slow path marking the object `ref` when it is gray. |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7074 | SlowPathCode* slow_path; |
| 7075 | if (always_update_field) { |
| 7076 | DCHECK(temp1 != nullptr); |
| 7077 | DCHECK(temp2 != nullptr); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7078 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86_64( |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7079 | instruction, ref, obj, src, /* unpoison_ref_before_marking */ true, *temp1, *temp2); |
| 7080 | } else { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7081 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86_64( |
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7082 | instruction, ref, /* unpoison_ref_before_marking */ true); |
| 7083 | } |
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7084 | AddSlowPath(slow_path); |
| 7085 | |
| 7086 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 7087 | __ j(kNotZero, slow_path->GetEntryLabel()); |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7088 | |
| 7089 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7090 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7091 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7092 | __ Bind(slow_path->GetExitLabel()); |
| 7093 | } |
| 7094 | |
| 7095 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7096 | Location out, |
| 7097 | Location ref, |
| 7098 | Location obj, |
| 7099 | uint32_t offset, |
| 7100 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7101 | DCHECK(kEmitCompilerReadBarrier); |
| 7102 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7103 | // Insert a slow path based read barrier *after* the reference load. |
| 7104 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7105 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7106 | // reference will be carried out by the runtime within the slow |
| 7107 | // path. |
| 7108 | // |
| 7109 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7110 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7111 | // not used by the artReadBarrierSlow entry point. |
| 7112 | // |
| 7113 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7114 | SlowPathCode* slow_path = new (GetScopedAllocator()) |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7115 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 7116 | AddSlowPath(slow_path); |
| 7117 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7118 | __ jmp(slow_path->GetEntryLabel()); |
| 7119 | __ Bind(slow_path->GetExitLabel()); |
| 7120 | } |
| 7121 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7122 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7123 | Location out, |
| 7124 | Location ref, |
| 7125 | Location obj, |
| 7126 | uint32_t offset, |
| 7127 | Location index) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7128 | if (kEmitCompilerReadBarrier) { |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7129 | // Baker's read barriers shall be handled by the fast path |
| 7130 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 7131 | DCHECK(!kUseBakerReadBarrier); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7132 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7133 | // by the runtime within the slow path. |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7134 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7135 | } else if (kPoisonHeapReferences) { |
| 7136 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 7137 | } |
| 7138 | } |
| 7139 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7140 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7141 | Location out, |
| 7142 | Location root) { |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7143 | DCHECK(kEmitCompilerReadBarrier); |
| 7144 | |
| Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 7145 | // Insert a slow path based read barrier *after* the GC root load. |
| 7146 | // |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7147 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7148 | // not need to do anything special for this here. |
| 7149 | SlowPathCode* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7150 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7151 | AddSlowPath(slow_path); |
| 7152 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7153 | __ jmp(slow_path->GetEntryLabel()); |
| 7154 | __ Bind(slow_path->GetExitLabel()); |
| 7155 | } |
| 7156 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7157 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7158 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7159 | LOG(FATAL) << "Unreachable"; |
| 7160 | } |
| 7161 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7162 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7163 | // Nothing to do, this should be removed during prepare for register allocator. |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7164 | LOG(FATAL) << "Unreachable"; |
| 7165 | } |
| 7166 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7167 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7168 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7169 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7170 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7171 | locations->SetInAt(0, Location::RequiresRegister()); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7172 | locations->AddTemp(Location::RequiresRegister()); |
| 7173 | locations->AddTemp(Location::RequiresRegister()); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7174 | } |
| 7175 | |
| 7176 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7177 | int32_t lower_bound = switch_instr->GetStartValue(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7178 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7179 | LocationSummary* locations = switch_instr->GetLocations(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7180 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 7181 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 7182 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7183 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7184 | |
| 7185 | // Should we generate smaller inline compare/jumps? |
| 7186 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7187 | // Figure out the correct compare values and jump conditions. |
| 7188 | // Handle the first compare/branch as a special case because it might |
| 7189 | // jump to the default case. |
| 7190 | DCHECK_GT(num_entries, 2u); |
| 7191 | Condition first_condition; |
| 7192 | uint32_t index; |
| 7193 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 7194 | if (lower_bound != 0) { |
| 7195 | first_condition = kLess; |
| 7196 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 7197 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7198 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 7199 | |
| 7200 | index = 1; |
| 7201 | } else { |
| 7202 | // Handle all the compare/jumps below. |
| 7203 | first_condition = kBelow; |
| 7204 | index = 0; |
| 7205 | } |
| 7206 | |
| 7207 | // Handle the rest of the compare/jumps. |
| 7208 | for (; index + 1 < num_entries; index += 2) { |
| 7209 | int32_t compare_to_value = lower_bound + index + 1; |
| 7210 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 7211 | // Jump to successors[index] if value < case_value[index]. |
| 7212 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7213 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7214 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7215 | } |
| 7216 | |
| 7217 | if (index != num_entries) { |
| 7218 | // There are an odd number of entries. Handle the last one. |
| 7219 | DCHECK_EQ(index + 1, num_entries); |
| Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 7220 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7221 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 7222 | } |
| 7223 | |
| 7224 | // And the default for any other value. |
| 7225 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 7226 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 7227 | } |
| 7228 | return; |
| 7229 | } |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7230 | |
| 7231 | // Remove the bias, if needed. |
| 7232 | Register value_reg_out = value_reg_in.AsRegister(); |
| 7233 | if (lower_bound != 0) { |
| 7234 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 7235 | value_reg_out = temp_reg.AsRegister(); |
| 7236 | } |
| 7237 | CpuRegister value_reg(value_reg_out); |
| 7238 | |
| 7239 | // Is the value in range? |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7240 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7241 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7242 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7243 | // We are in the range of the table. |
| 7244 | // Load the address of the jump table in the constant area. |
| 7245 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7246 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7247 | // Load the (signed) offset from the jump table. |
| 7248 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 7249 | |
| 7250 | // Add the offset to the address of the table base. |
| 7251 | __ addq(temp_reg, base_reg); |
| 7252 | |
| 7253 | // And jump. |
| 7254 | __ jmp(temp_reg); |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7255 | } |
| 7256 | |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7257 | void LocationsBuilderX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7258 | ATTRIBUTE_UNUSED) { |
| 7259 | LOG(FATAL) << "Unreachable"; |
| 7260 | } |
| 7261 | |
| 7262 | void InstructionCodeGeneratorX86_64::VisitIntermediateAddress(HIntermediateAddress* instruction |
| 7263 | ATTRIBUTE_UNUSED) { |
| 7264 | LOG(FATAL) << "Unreachable"; |
| 7265 | } |
| 7266 | |
| Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7267 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 7268 | if (value == 0) { |
| 7269 | __ xorl(dest, dest); |
| 7270 | } else { |
| 7271 | __ movl(dest, Immediate(value)); |
| 7272 | } |
| 7273 | } |
| 7274 | |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7275 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 7276 | if (value == 0) { |
| Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 7277 | // Clears upper bits too. |
| Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 7278 | __ xorl(dest, dest); |
| Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 7279 | } else if (IsUint<32>(value)) { |
| 7280 | // 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] | 7281 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 7282 | } else { |
| 7283 | __ movq(dest, Immediate(value)); |
| 7284 | } |
| 7285 | } |
| 7286 | |
| Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 7287 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 7288 | if (value == 0) { |
| 7289 | __ xorps(dest, dest); |
| 7290 | } else { |
| 7291 | __ movss(dest, LiteralInt32Address(value)); |
| 7292 | } |
| 7293 | } |
| 7294 | |
| 7295 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 7296 | if (value == 0) { |
| 7297 | __ xorpd(dest, dest); |
| 7298 | } else { |
| 7299 | __ movsd(dest, LiteralInt64Address(value)); |
| 7300 | } |
| 7301 | } |
| 7302 | |
| 7303 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 7304 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 7305 | } |
| 7306 | |
| 7307 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 7308 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 7309 | } |
| 7310 | |
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7311 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 7312 | if (value == 0) { |
| 7313 | __ testl(dest, dest); |
| 7314 | } else { |
| 7315 | __ cmpl(dest, Immediate(value)); |
| 7316 | } |
| 7317 | } |
| 7318 | |
| 7319 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 7320 | if (IsInt<32>(value)) { |
| 7321 | if (value == 0) { |
| 7322 | __ testq(dest, dest); |
| 7323 | } else { |
| 7324 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 7325 | } |
| 7326 | } else { |
| 7327 | // Value won't fit in an int. |
| 7328 | __ cmpq(dest, LiteralInt64Address(value)); |
| 7329 | } |
| 7330 | } |
| 7331 | |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7332 | void CodeGeneratorX86_64::GenerateIntCompare(Location lhs, Location rhs) { |
| 7333 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7334 | GenerateIntCompare(lhs_reg, rhs); |
| 7335 | } |
| 7336 | |
| 7337 | void CodeGeneratorX86_64::GenerateIntCompare(CpuRegister lhs, Location rhs) { |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7338 | if (rhs.IsConstant()) { |
| 7339 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7340 | Compare32BitValue(lhs, value); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7341 | } else if (rhs.IsStackSlot()) { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7342 | __ cmpl(lhs, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7343 | } else { |
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7344 | __ cmpl(lhs, rhs.AsRegister<CpuRegister>()); |
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7345 | } |
| 7346 | } |
| 7347 | |
| 7348 | void CodeGeneratorX86_64::GenerateLongCompare(Location lhs, Location rhs) { |
| 7349 | CpuRegister lhs_reg = lhs.AsRegister<CpuRegister>(); |
| 7350 | if (rhs.IsConstant()) { |
| 7351 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 7352 | Compare64BitValue(lhs_reg, value); |
| 7353 | } else if (rhs.IsDoubleStackSlot()) { |
| 7354 | __ cmpq(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 7355 | } else { |
| 7356 | __ cmpq(lhs_reg, rhs.AsRegister<CpuRegister>()); |
| 7357 | } |
| 7358 | } |
| 7359 | |
| 7360 | Address CodeGeneratorX86_64::ArrayAddress(CpuRegister obj, |
| 7361 | Location index, |
| 7362 | ScaleFactor scale, |
| 7363 | uint32_t data_offset) { |
| 7364 | return index.IsConstant() ? |
| 7365 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7366 | Address(obj, index.AsRegister<CpuRegister>(), scale, data_offset); |
| 7367 | } |
| 7368 | |
| Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 7369 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 7370 | DCHECK(dest.IsDoubleStackSlot()); |
| 7371 | if (IsInt<32>(value)) { |
| 7372 | // Can move directly as an int32 constant. |
| 7373 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 7374 | Immediate(static_cast<int32_t>(value))); |
| 7375 | } else { |
| 7376 | Load64BitValue(CpuRegister(TMP), value); |
| 7377 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 7378 | } |
| 7379 | } |
| 7380 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7381 | /** |
| 7382 | * Class to handle late fixup of offsets into constant area. |
| 7383 | */ |
| 7384 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 7385 | public: |
| 7386 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 7387 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7388 | |
| 7389 | protected: |
| 7390 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7391 | |
| 7392 | CodeGeneratorX86_64* codegen_; |
| 7393 | |
| 7394 | private: |
| 7395 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7396 | // Patch the correct offset for the instruction. We use the address of the |
| 7397 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 7398 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7399 | int32_t relative_position = constant_offset - pos; |
| 7400 | |
| 7401 | // Patch in the right value. |
| 7402 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7403 | } |
| 7404 | |
| 7405 | // Location in constant area that the fixup refers to. |
| 7406 | size_t offset_into_constant_area_; |
| 7407 | }; |
| 7408 | |
| 7409 | /** |
| 7410 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7411 | * constant area. |
| 7412 | */ |
| 7413 | class JumpTableRIPFixup : public RIPFixup { |
| 7414 | public: |
| 7415 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 7416 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 7417 | |
| 7418 | void CreateJumpTable() { |
| 7419 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 7420 | |
| 7421 | // Ensure that the reference to the jump table has the correct offset. |
| 7422 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7423 | SetOffset(offset_in_constant_table); |
| 7424 | |
| 7425 | // Compute the offset from the start of the function to this jump table. |
| 7426 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 7427 | |
| 7428 | // Populate the jump table with the correct values for the jump table. |
| 7429 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7430 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7431 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7432 | // The value that we want is the target offset - the position of the table. |
| 7433 | for (int32_t i = 0; i < num_entries; i++) { |
| 7434 | HBasicBlock* b = successors[i]; |
| 7435 | Label* l = codegen_->GetLabelOf(b); |
| 7436 | DCHECK(l->IsBound()); |
| 7437 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 7438 | assembler->AppendInt32(offset_to_block); |
| 7439 | } |
| 7440 | } |
| 7441 | |
| 7442 | private: |
| 7443 | const HPackedSwitch* switch_instr_; |
| 7444 | }; |
| 7445 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7446 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 7447 | // Generate the constant area if needed. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7448 | X86_64Assembler* assembler = GetAssembler(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7449 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7450 | // 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] | 7451 | assembler->Align(4, 0); |
| 7452 | constant_area_start_ = assembler->CodeSize(); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7453 | |
| 7454 | // Populate any jump tables. |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7455 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7456 | jump_table->CreateJumpTable(); |
| 7457 | } |
| 7458 | |
| 7459 | // And now add the constant area to the generated code. |
| Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 7460 | assembler->AddConstantArea(); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7461 | } |
| 7462 | |
| 7463 | // And finish up. |
| 7464 | CodeGenerator::Finalize(allocator); |
| 7465 | } |
| 7466 | |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7467 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7468 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddDouble(v)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7469 | return Address::RIP(fixup); |
| 7470 | } |
| 7471 | |
| 7472 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7473 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddFloat(v)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7474 | return Address::RIP(fixup); |
| 7475 | } |
| 7476 | |
| 7477 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7478 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt32(v)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7479 | return Address::RIP(fixup); |
| 7480 | } |
| 7481 | |
| 7482 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7483 | AssemblerFixup* fixup = new (GetGraph()->GetAllocator()) RIPFixup(*this, __ AddInt64(v)); |
| Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 7484 | return Address::RIP(fixup); |
| 7485 | } |
| 7486 | |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7487 | // TODO: trg as memory. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7488 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, DataType::Type type) { |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7489 | if (!trg.IsValid()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7490 | DCHECK_EQ(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7491 | return; |
| 7492 | } |
| 7493 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7494 | DCHECK_NE(type, DataType::Type::kVoid); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7495 | |
| 7496 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 7497 | if (trg.Equals(return_loc)) { |
| 7498 | return; |
| 7499 | } |
| 7500 | |
| 7501 | // Let the parallel move resolver take care of all of this. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7502 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7503 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 7504 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7505 | } |
| 7506 | |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7507 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 7508 | // Create a fixup to be used to create and address the jump table. |
| 7509 | JumpTableRIPFixup* table_fixup = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7510 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); |
| Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 7511 | |
| 7512 | // We have to populate the jump tables. |
| 7513 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7514 | return Address::RIP(table_fixup); |
| 7515 | } |
| 7516 | |
| Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 7517 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 7518 | const Address& addr_high, |
| 7519 | int64_t v, |
| 7520 | HInstruction* instruction) { |
| 7521 | if (IsInt<32>(v)) { |
| 7522 | int32_t v_32 = v; |
| 7523 | __ movq(addr_low, Immediate(v_32)); |
| 7524 | MaybeRecordImplicitNullCheck(instruction); |
| 7525 | } else { |
| 7526 | // Didn't fit in a register. Do it in pieces. |
| 7527 | int32_t low_v = Low32Bits(v); |
| 7528 | int32_t high_v = High32Bits(v); |
| 7529 | __ movl(addr_low, Immediate(low_v)); |
| 7530 | MaybeRecordImplicitNullCheck(instruction); |
| 7531 | __ movl(addr_high, Immediate(high_v)); |
| 7532 | } |
| 7533 | } |
| 7534 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7535 | void CodeGeneratorX86_64::PatchJitRootUse(uint8_t* code, |
| 7536 | const uint8_t* roots_data, |
| 7537 | const PatchInfo<Label>& info, |
| 7538 | uint64_t index_in_table) const { |
| 7539 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 7540 | uintptr_t address = |
| 7541 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 7542 | typedef __attribute__((__aligned__(1))) uint32_t unaligned_uint32_t; |
| 7543 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = |
| 7544 | dchecked_integral_cast<uint32_t>(address); |
| 7545 | } |
| 7546 | |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7547 | void CodeGeneratorX86_64::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 7548 | for (const PatchInfo<Label>& info : jit_string_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7549 | 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] | 7550 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7551 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7552 | } |
| 7553 | |
| 7554 | for (const PatchInfo<Label>& info : jit_class_patches_) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7555 | 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] | 7556 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 7557 | PatchJitRootUse(code, roots_data, info, index_in_table); |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 7558 | } |
| 7559 | } |
| 7560 | |
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7561 | #undef __ |
| 7562 | |
| Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 7563 | } // namespace x86_64 |
| 7564 | } // namespace art |